mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
commit
e12f266f54
@ -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
|
||||
|
@ -15,6 +15,7 @@ use Rector\Console\Shell;
|
||||
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 @@ final class ProcessCommand extends AbstractCommand
|
||||
ReportingExtensionRunner $reportingExtensionRunner,
|
||||
RectorNodeTraverser $rectorNodeTraverser,
|
||||
StubLoader $stubLoader,
|
||||
Linter $linter,
|
||||
array $paths,
|
||||
array $fileExtensions
|
||||
) {
|
||||
@ -114,9 +121,10 @@ final class ProcessCommand extends AbstractCommand
|
||||
$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 @@ final class ProcessCommand extends AbstractCommand
|
||||
$this->configuration->mustMatchGitDiff()
|
||||
);
|
||||
|
||||
foreach ($phpFileInfos as $phpFileInfo) {
|
||||
$this->linter->lintFile($phpFileInfo);
|
||||
}
|
||||
|
||||
$this->additionalAutoloader->autoloadWithInputAndSource($input, $source);
|
||||
|
||||
$this->rectorApplication->runOnFileInfos($phpFileInfos);
|
||||
|
11
src/Exception/Linter/LintingException.php
Normal file
11
src/Exception/Linter/LintingException.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Exception\Linter;
|
||||
|
||||
use Exception;
|
||||
|
||||
final class LintingException extends Exception
|
||||
{
|
||||
}
|
43
src/Linter/Linter.php
Normal file
43
src/Linter/Linter.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Linter;
|
||||
|
||||
use Rector\Exception\Linter\LintingException;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
/**
|
||||
* Inspired by https://github.com/keradus/PHP-CS-Fixer/blob/a838434c7584e4744e2fca9950687d5326212560/Symfony/CS/Linter/Linter.php
|
||||
*/
|
||||
final class Linter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $executable;
|
||||
|
||||
public function __construct(PhpExecutableFinder $phpExecutableFinder)
|
||||
{
|
||||
$executable = $phpExecutableFinder->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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user