mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-23 19:24:48 +01:00
ensure rectors are loaded in ProcessCommand
This commit is contained in:
parent
0d05e11bce
commit
998fc08a3b
@ -4,7 +4,9 @@ namespace Rector\Console\Command;
|
|||||||
|
|
||||||
use Nette\Utils\Finder;
|
use Nette\Utils\Finder;
|
||||||
use Rector\Application\FileProcessor;
|
use Rector\Application\FileProcessor;
|
||||||
|
use Rector\Exception\NoRectorsLoadedException;
|
||||||
use Rector\Naming\CommandNaming;
|
use Rector\Naming\CommandNaming;
|
||||||
|
use Rector\Rector\RectorCollector;
|
||||||
use SplFileInfo;
|
use SplFileInfo;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
@ -23,9 +25,15 @@ final class ProcessCommand extends Command
|
|||||||
*/
|
*/
|
||||||
private $fileProcessor;
|
private $fileProcessor;
|
||||||
|
|
||||||
public function __construct(FileProcessor $fileProcessor)
|
/**
|
||||||
|
* @var RectorCollector
|
||||||
|
*/
|
||||||
|
private $rectorCollector;
|
||||||
|
|
||||||
|
public function __construct(FileProcessor $fileProcessor, RectorCollector $rectorCollector)
|
||||||
{
|
{
|
||||||
$this->fileProcessor = $fileProcessor;
|
$this->fileProcessor = $fileProcessor;
|
||||||
|
$this->rectorCollector = $rectorCollector;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -43,6 +51,8 @@ final class ProcessCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
|
$this->ensureSomeRectorsAreRegistered();
|
||||||
|
|
||||||
$source = $input->getArgument(self::ARGUMENT_SOURCE_NAME);
|
$source = $input->getArgument(self::ARGUMENT_SOURCE_NAME);
|
||||||
$files = $this->findPhpFilesInDirectories($source);
|
$files = $this->findPhpFilesInDirectories($source);
|
||||||
$this->fileProcessor->processFiles($files);
|
$this->fileProcessor->processFiles($files);
|
||||||
@ -61,4 +71,16 @@ final class ProcessCommand extends Command
|
|||||||
|
|
||||||
return iterator_to_array($finder->getIterator());
|
return iterator_to_array($finder->getIterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function ensureSomeRectorsAreRegistered(): void
|
||||||
|
{
|
||||||
|
if ($this->rectorCollector->getRectorCount() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoRectorsLoadedException(
|
||||||
|
'No rector were found. Registers them in rector.yml config to "rector:" '
|
||||||
|
. 'section or load them via "--config <file>.yml" CLI option.'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
10
src/Exception/NoRectorsLoadedException.php
Normal file
10
src/Exception/NoRectorsLoadedException.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Rector\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
final class NoRectorsLoadedException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user