diff --git a/config/services.yaml b/config/services.yaml index fa2761468881..3193af005278 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -23,6 +23,7 @@ services: alias: 'Rector\Console\Application' Symfony\Component\Console\Descriptor\TextDescriptor: null + Symfony\Component\Process\PhpExecutableFinder: null # PhpParser - Parser PhpParser\ParserFactory: null diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index fd5207d40e06..711eb9360f27 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -15,6 +15,7 @@ use Rector\Extension\ReportingExtensionRunner; use Rector\FileSystem\FilesFinder; use Rector\Guard\RectorGuard; +use Rector\Linter\Linter; use Rector\PhpParser\NodeTraverser\RectorNodeTraverser; use Rector\Stubs\StubLoader; use Symfony\Component\Console\Input\InputArgument; @@ -85,6 +86,11 @@ final class ProcessCommand extends AbstractCommand */ private $paths = []; + /** + * @var Linter + */ + private $linter; + /** * @param string[] $paths * @param string[] $fileExtensions @@ -100,6 +106,7 @@ public function __construct( ReportingExtensionRunner $reportingExtensionRunner, RectorNodeTraverser $rectorNodeTraverser, StubLoader $stubLoader, + Linter $linter, array $paths, array $fileExtensions ) { @@ -114,9 +121,10 @@ public function __construct( $this->reportingExtensionRunner = $reportingExtensionRunner; $this->rectorNodeTraverser = $rectorNodeTraverser; $this->stubLoader = $stubLoader; + $this->paths = $paths; + $this->linter = $linter; parent::__construct(); - $this->paths = $paths; } protected function configure(): void @@ -203,6 +211,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->configuration->mustMatchGitDiff() ); + foreach ($phpFileInfos as $phpFileInfo) { + $this->linter->lintFile($phpFileInfo); + } + $this->additionalAutoloader->autoloadWithInputAndSource($input, $source); $this->rectorApplication->runOnFileInfos($phpFileInfos); diff --git a/src/Exception/Linter/LintingException.php b/src/Exception/Linter/LintingException.php new file mode 100644 index 000000000000..dc6bea4567ba --- /dev/null +++ b/src/Exception/Linter/LintingException.php @@ -0,0 +1,11 @@ +find(); + if ($executable === false) { + throw new LintingException('PHP executable was not found'); + } + + $this->executable = $executable; + } + + public function lintFile(SmartFileInfo $smartFileInfo): void + { + $process = new Process([$this->executable, '-l', $smartFileInfo->getRealPath()]); + $process->run(); + + if ($process->isSuccessful()) { + return; + } + + throw new LintingException($process->getOutput(), (int) $process->getExitCode()); + } +}