mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 02:40:50 +00:00
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Rector\Console\Command;
|
|
|
|
use Nette\Utils\Finder;
|
|
use Rector\Application\FileProcessor;
|
|
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;
|
|
|
|
final class ReconstructCommand extends Command
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private const NAME = 'reconstruct';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private const ARGUMENT_SOURCE_NAME = 'source';
|
|
|
|
/**
|
|
* @var FileProcessor
|
|
*/
|
|
private $fileProcessor;
|
|
|
|
public function __construct(FileProcessor $fileProcessor)
|
|
{
|
|
$this->fileProcessor = $fileProcessor;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->setName(self::NAME);
|
|
$this->setDescription('Reconstruct set of your code.');
|
|
$this->addArgument(
|
|
self::ARGUMENT_SOURCE_NAME,
|
|
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
|
|
'The path(s) to be checked.'
|
|
);
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$source = $input->getArgument(self::ARGUMENT_SOURCE_NAME);
|
|
$files = $this->findPhpFilesInDirectories($source);
|
|
$this->fileProcessor->processFiles($files);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @param string[] $directories
|
|
* @return SplFileInfo[] array
|
|
*/
|
|
private function findPhpFilesInDirectories(array $directories): array
|
|
{
|
|
$finder = Finder::find('*.php')
|
|
->in($directories);
|
|
|
|
return iterator_to_array($finder->getIterator());
|
|
}
|
|
}
|