diff --git a/full-tool-build.sh b/full-tool-build.sh old mode 100644 new mode 100755 index ab51052..949d3a0 --- a/full-tool-build.sh +++ b/full-tool-build.sh @@ -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 diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index f015e03..ab60cf3 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -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'); @@ -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'); @@ -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())); @@ -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); diff --git a/src/Process/AnalyseProcessFactory.php b/src/Process/AnalyseProcessFactory.php index f7d8ef1..de9bbf3 100644 --- a/src/Process/AnalyseProcessFactory.php +++ b/src/Process/AnalyseProcessFactory.php @@ -22,7 +22,7 @@ final class AnalyseProcessFactory /** * @param array $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); @@ -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