diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index b56c05df1fb..c6a1b2477f3 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -5,15 +5,14 @@ namespace Rector\Console\Command; use Rector\Application\FileProcessor; use Rector\Exception\FileSystem\DirectoryNotFoundException; use Rector\Exception\NoRectorsLoadedException; +use Rector\FileSystem\PhpFilesFinder; use Rector\Naming\CommandNaming; use Rector\Rector\RectorCollector; -use SplFileInfo; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Finder\Finder; final class ProcessCommand extends Command { @@ -36,15 +35,21 @@ final class ProcessCommand extends Command * @var SymfonyStyle */ private $symfonyStyle; + /** + * @var PhpFilesFinder + */ + private $phpFilesFinder; public function __construct( FileProcessor $fileProcessor, RectorCollector $rectorCollector, - SymfonyStyle $symfonyStyle + SymfonyStyle $symfonyStyle, + PhpFilesFinder $phpFilesFinder ) { $this->fileProcessor = $fileProcessor; $this->rectorCollector = $rectorCollector; $this->symfonyStyle = $symfonyStyle; + $this->phpFilesFinder = $phpFilesFinder; parent::__construct(); } @@ -67,7 +72,7 @@ final class ProcessCommand extends Command $this->ensureSomeRectorsAreRegistered(); - $files = $this->findPhpFilesInDirectories($source); + $files = $this->phpFilesFinder->findInDirectories($source); $this->reportFoundFiles($files); @@ -80,23 +85,6 @@ final class ProcessCommand extends Command return 0; } - /** - * @param string[] $directories - * @return SplFileInfo[] array - */ - private function findPhpFilesInDirectories(array $directories): array - { - $finder = Finder::create() - ->files() - ->name('*.php') - ->exclude('examples') - ->exclude('tests') - ->exclude('Tests') - ->in($directories); - - return iterator_to_array($finder->getIterator()); - } - private function ensureSomeRectorsAreRegistered(): void { if ($this->rectorCollector->getRectorCount() > 0) { diff --git a/src/FileSystem/PhpFilesFinder.php b/src/FileSystem/PhpFilesFinder.php new file mode 100644 index 00000000000..94fa65b4758 --- /dev/null +++ b/src/FileSystem/PhpFilesFinder.php @@ -0,0 +1,27 @@ +files() + ->name('*.php') + ->exclude('examples') + ->exclude('tests') + ->exclude('Tests') + ->exclude('Test') + ->in($directories); + + return iterator_to_array($finder->getIterator()); + } +}