Skip to content

Commit

Permalink
add phpstan timeout option (#29)
Browse files Browse the repository at this point in the history
* add option for phpstan timeout

* build script: suppress composer dev requirement hint and cleanup previous temp dir

* fix nullable $phpstanTimeout
  • Loading branch information
npo-mmenke authored Aug 8, 2024
1 parent 3783dac commit 18d7de5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion full-tool-build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ composer install --ansi
composer update --no-dev --ansi

# downgrade with rector
rm -rf rector-local
mkdir rector-local
composer require rector/rector --working-dir rector-local
composer require rector/rector --working-dir rector-local --no-interaction
rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php-72.php --ansi

# prefix
Expand Down
11 changes: 6 additions & 5 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function configure(): void

$this->addOption('min-level', null, InputOption::VALUE_REQUIRED, 'Min PHPStan level to run', 0);
$this->addOption('max-level', null, InputOption::VALUE_REQUIRED, 'Max PHPStan level to run', 8);

$this->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Set PHPStan process timeout in seconds');
$this->addOption('env-file', null, InputOption::VALUE_REQUIRED, 'Path to project .env file');
$this->addOption('json', null, InputOption::VALUE_NONE, 'Show result in JSON');

Expand All @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$minPhpStanLevel = (int) $input->getOption('min-level');
$maxPhpStanLevel = (int) $input->getOption('max-level');
Assert::lessThanEq($minPhpStanLevel, $maxPhpStanLevel);

$phpStanTimeout = $input->getOption('timeout') ? (int) $input->getOption('timeout') : null;
$isBare = (bool) $input->getOption('bare');
$isJson = (bool) $input->getOption('json');
$isNoIgnore = (bool) $input->getOption('no-ignore');
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
usleep(700_000);
}

$levelResult = $this->measureErrorCountInLevel($phpStanLevel, $projectDirectory, $envVariables);
$levelResult = $this->measureErrorCountInLevel($phpStanLevel, $projectDirectory, $envVariables, $phpStanTimeout);
$levelResults[] = $levelResult;

$section->overwrite(sprintf($infoMessage . ': found %d errors', $levelResult->getErrorCount()));
Expand Down Expand Up @@ -150,9 +150,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
private function measureErrorCountInLevel(
int $phpStanLevel,
string $projectDirectory,
array $envVariables
array $envVariables,
?int $phpStanTimeout
): LevelResult {
$process = $this->analyseProcessFactory->create($projectDirectory, $phpStanLevel, $envVariables);
$process = $this->analyseProcessFactory->create($projectDirectory, $phpStanLevel, $envVariables, $phpStanTimeout);
$process->run();

$result = $this->phpStanResultResolver->resolve($process);
Expand Down
6 changes: 4 additions & 2 deletions src/Process/AnalyseProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class AnalyseProcessFactory
/**
* @param array<string, mixed> $envVariables
*/
public function create(string $projectDirectory, int $phpStanLevel, array $envVariables): Process
public function create(string $projectDirectory, int $phpStanLevel, array $envVariables, ?int $phpStanTimeout = self::TIMEOUT_IN_SECONDS): Process
{
$phpStanBinFilePath = ComposerLoader::getPHPStanBinFile($projectDirectory);

Expand All @@ -34,13 +34,15 @@ public function create(string $projectDirectory, int $phpStanLevel, array $envVa
// increase default memory limit to allow analyse huge projects
'--memory-limit',
self::MEMORY_LIMIT,
'--timeout',
$phpStanTimeout,
'--level',
$phpStanLevel,
'--configuration',
'phpstan-bodyscan.neon',
];

return new Process($command, $projectDirectory, $envVariables, null, self::TIMEOUT_IN_SECONDS);
return new Process($command, $projectDirectory, $envVariables, null, $phpStanTimeout);
}

public function createTypeCoverageProcess(string $projectDirectory): Process
Expand Down

0 comments on commit 18d7de5

Please sign in to comment.