Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,45 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('analyze', 'Run all enabled tools.')]
final class AnalyzeCommand extends Command
{
public function __construct(
private Configuration $configuration,
private readonly Configuration $configuration,
) {
parent::__construct();
}

protected function configure(): void
{
$this->addOption(
'format',
null,
InputOption::VALUE_OPTIONAL,
'Output format to use (by supported commands).',
);
$this->addOption(
'working-dir',
null,
InputOption::VALUE_OPTIONAL,
'Working directory, relative to project root.',
);
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
if (null === $workingDir = $input->getOption('working-dir')) {
return;
}

\assert(\is_string($workingDir));

$this->configuration->setWorkingDir($workingDir);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CodesnifferCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'phpcs.xml.dist')
|| \is_file($configuration->getRootDir() . 'phpcs.xml');
return \is_file($configuration->getWorkingDir() . 'phpcs.xml.dist')
|| \is_file($configuration->getWorkingDir() . 'phpcs.xml');
}
}
19 changes: 18 additions & 1 deletion src/Command/DevToolsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ protected function configure(): void
InputOption::VALUE_OPTIONAL,
'Output format to use (by supported commands).',
);
$this->addOption(
'working-dir',
null,
InputOption::VALUE_OPTIONAL,
'Working directory, relative to project root.',
);
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
if (null === $workingDir = $input->getOption('working-dir')) {
return;
}

\assert(\is_string($workingDir));

$this->configuration->setWorkingDir($workingDir);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down Expand Up @@ -71,7 +88,7 @@ protected function isGitHubFormat(InputInterface $input): bool

protected function withBinPath(string $command): string
{
return $this->configuration->getRootDir() . 'bin/' . $command;
return $this->configuration->getWorkingDir() . 'bin/' . $command;
}

protected function withVendorBinPath(string $command): string
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DoctrineMigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ protected function getMultiProcess(InputInterface $input): array

public static function isAvailable(Configuration $configuration): bool
{
if (!\is_file($configuration->getRootDir() . 'bin/console')) {
if (!\is_file($configuration->getWorkingDir() . 'bin/console')) {
return false;
}

$process = new Process([$configuration->getRootDir() . 'bin/console', 'list', '--env=test']);
$process = new Process([$configuration->getWorkingDir() . 'bin/console', 'list', '--env=test']);
$process->run();

return \str_contains($process->getOutput(), 'doctrine:migrations:migrate');
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DoctrineValidateSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ protected function getProcess(InputInterface $input): Process

public static function isAvailable(Configuration $configuration): bool
{
if (!\is_file($configuration->getRootDir() . 'bin/console')) {
if (!\is_file($configuration->getWorkingDir() . 'bin/console')) {
return false;
}

$process = new Process([$configuration->getRootDir() . 'bin/console', 'list']);
$process = new Process([$configuration->getWorkingDir() . 'bin/console', 'list']);
$process->run();

return \str_contains($process->getOutput(), 'doctrine:schema:validate');
Expand Down
4 changes: 2 additions & 2 deletions src/Command/LintSymfonyContainerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ protected function getProcess(InputInterface $input): Process

public static function isAvailable(Configuration $configuration): bool
{
if (!\is_file($configuration->getRootDir() . 'bin/console')) {
if (!\is_file($configuration->getWorkingDir() . 'bin/console')) {
return false;
}

$process = new Process([$configuration->getRootDir() . 'bin/console', 'list']);
$process = new Process([$configuration->getWorkingDir() . 'bin/console', 'list']);
$process->run();

return \str_contains($process->getOutput(), 'lint:container');
Expand Down
6 changes: 3 additions & 3 deletions src/Command/LintYamlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ protected function getProcess(InputInterface $input): Process
public static function isAvailable(Configuration $configuration): bool
{
if (
!\is_file($configuration->getRootDir() . 'bin/console') ||
!\is_dir($configuration->getRootDir() . 'config')
!\is_file($configuration->getWorkingDir() . 'bin/console') ||
!\is_dir($configuration->getWorkingDir() . 'config')
) {
return false;
}

$process = new Process([$configuration->getRootDir() . 'bin/console', 'list']);
$process = new Process([$configuration->getWorkingDir() . 'bin/console', 'list']);
$process->run();

return \str_contains($process->getOutput(), 'lint:yaml');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/PhpArkitectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'phparkitect.php');
return \is_file($configuration->getWorkingDir() . 'phparkitect.php');
}
}
4 changes: 2 additions & 2 deletions src/Command/PhpStanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'phpstan.neon.dist')
|| \is_file($configuration->getRootDir() . 'phpstan.neon');
return \is_file($configuration->getWorkingDir() . 'phpstan.neon.dist')
|| \is_file($configuration->getWorkingDir() . 'phpstan.neon');
}
}
4 changes: 2 additions & 2 deletions src/Command/PhpUnitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'phpunit.xml.dist')
|| \is_file($configuration->getRootDir() . 'phpunit.xml');
return \is_file($configuration->getWorkingDir() . 'phpunit.xml.dist')
|| \is_file($configuration->getWorkingDir() . 'phpunit.xml');
}
}
4 changes: 2 additions & 2 deletions src/Command/PsalmCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'psalm.xml.dist')
|| \is_file($configuration->getRootDir() . 'psalm.xml');
return \is_file($configuration->getWorkingDir() . 'psalm.xml.dist')
|| \is_file($configuration->getWorkingDir() . 'psalm.xml');
}
}
4 changes: 2 additions & 2 deletions src/Command/RoaveInfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function isAvailable(Configuration $configuration): bool
return false;
}

return \is_file($configuration->getRootDir() . 'infection.json.dist')
|| \is_file($configuration->getRootDir() . 'infection.json');
return \is_file($configuration->getWorkingDir() . 'infection.json.dist')
|| \is_file($configuration->getWorkingDir() . 'infection.json');
}
}
11 changes: 11 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class Configuration
private array|null $phpVersions = null;

private string $rootDir;
private string|null $workingDir = null;
private string|null $threads = null;

public function __construct()
Expand All @@ -42,6 +43,11 @@ public function __construct()
throw new \RuntimeException('Unable to determine project root');
}

public function setWorkingDir(string $workingDir): void
{
$this->workingDir = $this->rootDir . \trim($workingDir, '/') . '/';
}

/** @return array<string, class-string<DevToolsCommand>> */
public function getEnabledTools(): array
{
Expand Down Expand Up @@ -76,6 +82,11 @@ public function getThreads(): string
return $this->threads;
}

public function getWorkingDir(): string
{
return $this->workingDir ?? $this->rootDir;
}

private function determineThreads(): string
{
return \trim(
Expand Down