diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon index 454ebdfc47d..583aa02a35c 100644 --- a/easy-coding-standard.neon +++ b/easy-coding-standard.neon @@ -25,6 +25,7 @@ checkers: - 'Rector\DeprecationExtractor\Deprecation\*' - 'Rector\BetterReflection\SourceLocator\Located\LocatedSource' - 'phpDocumentor\Reflection\Types\*' + - 'Rector\Reporting\FileDiff' Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer: extra_skipped_classes: diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index fea29449ee8..88e21b90e2f 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -13,6 +13,7 @@ use Rector\Exception\NoRectorsLoadedException; use Rector\FileSystem\PhpFilesFinder; use Rector\Naming\CommandNaming; use Rector\Rector\RectorCollector; +use Rector\Reporting\FileDiff; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -65,9 +66,9 @@ final class ProcessCommand extends Command private $changedFiles = []; /** - * @var string[][] + * @var FileDiff[] */ - private $diffFiles = []; + private $fileDiffs = []; /** * @var AdditionalAutoloader @@ -136,7 +137,7 @@ final class ProcessCommand extends Command $this->processFiles($files); - $this->processCommandReporter->reportDiffFiles($this->diffFiles); + $this->processCommandReporter->reportFileDiffs($this->fileDiffs); $this->processCommandReporter->reportChangedFiles($this->changedFiles); $this->consoleStyle->success('Rector is done!'); @@ -189,10 +190,10 @@ final class ProcessCommand extends Command if ($this->parameterProvider->provideParameter(Option::OPTION_DRY_RUN)) { $newContent = $this->fileProcessor->processFileToString($fileInfo); if ($newContent !== $oldContent) { - $this->diffFiles[] = [ - 'file' => $fileInfo->getPathname(), - 'diff' => $this->differAndFormatter->diffAndFormat($oldContent, $newContent), - ]; + $this->fileDiffs[] = new FileDiff( + $fileInfo->getPathname(), + $this->differAndFormatter->diffAndFormat($oldContent, $newContent) + ); } } else { $newContent = $this->fileProcessor->processFile($fileInfo); diff --git a/src/Console/Output/ProcessCommandReporter.php b/src/Console/Output/ProcessCommandReporter.php index 81e6fe6ec59..f35e5844920 100644 --- a/src/Console/Output/ProcessCommandReporter.php +++ b/src/Console/Output/ProcessCommandReporter.php @@ -5,6 +5,7 @@ namespace Rector\Console\Output; use Rector\Console\ConsoleStyle; use Rector\Contract\Rector\RectorInterface; use Rector\Rector\RectorCollector; +use Rector\Reporting\FileDiff; final class ProcessCommandReporter { @@ -57,25 +58,25 @@ final class ProcessCommandReporter } /** - * @param string[][] $diffFiles + * @param FileDiff[] $fileDiffs */ - public function reportDiffFiles(array $diffFiles): void + public function reportFileDiffs(array $fileDiffs): void { - if (count($diffFiles) <= 0) { + if (count($fileDiffs) <= 0) { return; } $this->consoleStyle->title(sprintf( '%d file%s with changes', - count($diffFiles), - count($diffFiles) === 1 ? '' : 's' + count($fileDiffs), + count($fileDiffs) === 1 ? '' : 's' )); $i = 0; - foreach ($diffFiles as $diffFile) { - $this->consoleStyle->writeln(sprintf('%d) %s', ++$i, $diffFile['file'])); + foreach ($fileDiffs as $fileDiff) { + $this->consoleStyle->writeln(sprintf('%d) %s', ++$i, $fileDiff->getFile())); $this->consoleStyle->newLine(); - $this->consoleStyle->writeln($diffFile['diff']); + $this->consoleStyle->writeln($fileDiff->getDiff()); $this->consoleStyle->newLine(); } } diff --git a/src/Reporting/FileDiff.php b/src/Reporting/FileDiff.php new file mode 100644 index 00000000000..8453b57f3c7 --- /dev/null +++ b/src/Reporting/FileDiff.php @@ -0,0 +1,32 @@ +file = $file; + $this->diff = $diff; + } + + public function getDiff(): string + { + return $this->diff; + } + + public function getFile(): string + { + return $this->file; + } +} diff --git a/src/config/services.yml b/src/config/services.yml index b723dc70233..a714fc5cc09 100644 --- a/src/config/services.yml +++ b/src/config/services.yml @@ -5,7 +5,7 @@ services: Rector\: resource: '../' - exclude: '../{Node/Attribute.php,Rector/Contrib/**/*Rector.php,Rector/Dynamic,Rector/MagicDisclosure,Testing}' + exclude: '../{Node/Attribute.php,Rector/Contrib/**/*Rector.php,Rector/Dynamic,Rector/MagicDisclosure,Reporting/FileDiff.php,Testing}' Rector\Rector\Contrib\Symfony\Form\Helper\FormTypeStringToTypeProvider: ~