From 27078e79628cb14866b69dc6b8c2181fbec1d4c6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 9 Sep 2023 16:13:17 +0200 Subject: [PATCH] [DX] Add FileProcessResult + kick of collectors (#4947) --- .../expected-output.diff | 32 +++---- .../expected-output.diff | 32 +++---- .../expected-output.diff | 32 +++---- .../expected-output.diff | 30 +++---- .../expected-output.diff | 8 +- .../expected-output.diff | 8 +- .../expected-output.diff | 34 +++---- .../expected-output.diff | 34 +++---- ecs.php | 2 + .../Output/ConsoleOutputFormatter.php | 6 +- .../Output/JsonOutputFormatter.php | 6 +- .../Application/ParallelFileProcessor.php | 23 +++-- packages/Parallel/ValueObject/Bridge.php | 5 ++ packages/Parallel/WorkerRunner.php | 10 ++- ...dAllowDynamicPropertiesAttributeRector.php | 2 +- src/Application/ApplicationFileProcessor.php | 89 +++++++++---------- .../FileProcessor/PhpFileProcessor.php | 58 ++++-------- src/Console/Command/ProcessCommand.php | 13 ++- src/ValueObject/FileProcessResult.php | 44 +++++++++ src/ValueObject/ProcessResult.php | 39 +++++--- .../ProcessResultFactory.php | 24 ----- 21 files changed, 277 insertions(+), 254 deletions(-) create mode 100644 src/ValueObject/FileProcessResult.php delete mode 100644 src/ValueObjectFactory/ProcessResultFactory.php diff --git a/e2e/applied-rule-change-docblock/expected-output.diff b/e2e/applied-rule-change-docblock/expected-output.diff index 29d752ff30b..07dc467cbae 100644 --- a/e2e/applied-rule-change-docblock/expected-output.diff +++ b/e2e/applied-rule-change-docblock/expected-output.diff @@ -1,40 +1,40 @@ 2 files with changes ==================== -1) src/UselessVarTag.php:1 +1) src/RenameDocblock.php:0 ---------- begin diff ---------- @@ @@ + rules([\PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer::class]); + $ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, [ 'allow_mixed' => true, ]); diff --git a/packages/ChangesReporting/Output/ConsoleOutputFormatter.php b/packages/ChangesReporting/Output/ConsoleOutputFormatter.php index 08cd05edaa7..e3f162d07a8 100644 --- a/packages/ChangesReporting/Output/ConsoleOutputFormatter.php +++ b/packages/ChangesReporting/Output/ConsoleOutputFormatter.php @@ -27,7 +27,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface private const ON_LINE_REGEX = '# on line #'; public function __construct( - private readonly SymfonyStyle $symfonyStyle, + private readonly SymfonyStyle $symfonyStyle, private readonly RectorsChangelogResolver $rectorsChangelogResolver, ) { } @@ -38,9 +38,9 @@ public function report(ProcessResult $processResult, Configuration $configuratio $this->reportFileDiffs($processResult->getFileDiffs()); } - $this->reportErrors($processResult->getErrors()); + $this->reportErrors($processResult->getSystemErrors()); - if ($processResult->getErrors() !== []) { + if ($processResult->getSystemErrors() !== []) { return; } diff --git a/packages/ChangesReporting/Output/JsonOutputFormatter.php b/packages/ChangesReporting/Output/JsonOutputFormatter.php index 22f793025f2..6939caa53d2 100644 --- a/packages/ChangesReporting/Output/JsonOutputFormatter.php +++ b/packages/ChangesReporting/Output/JsonOutputFormatter.php @@ -55,10 +55,10 @@ public function report(ProcessResult $processResult, Configuration $configuratio $errorsJson['changed_files'][] = $relativeFilePath; } - $errors = $processResult->getErrors(); - $errorsJson['totals']['errors'] = count($errors); + $systemErrors = $processResult->getSystemErrors(); + $errorsJson['totals']['errors'] = count($systemErrors); - $errorsData = $this->createErrorsData($errors); + $errorsData = $this->createErrorsData($systemErrors); if ($errorsData !== []) { $errorsJson['errors'] = $errorsData; } diff --git a/packages/Parallel/Application/ParallelFileProcessor.php b/packages/Parallel/Application/ParallelFileProcessor.php index bdec5127ea6..6926b798866 100644 --- a/packages/Parallel/Application/ParallelFileProcessor.php +++ b/packages/Parallel/Application/ParallelFileProcessor.php @@ -7,6 +7,7 @@ use Clue\React\NDJson\Decoder; use Clue\React\NDJson\Encoder; use Nette\Utils\Random; +use PHPStan\Collectors\CollectedData; use React\EventLoop\StreamSelectLoop; use React\Socket\ConnectionInterface; use React\Socket\TcpServer; @@ -14,6 +15,7 @@ use Rector\Core\Configuration\Parameter\SimpleParameterProvider; use Rector\Core\Console\Command\ProcessCommand; use Rector\Core\ValueObject\Error\SystemError; +use Rector\Core\ValueObject\ProcessResult; use Rector\Core\ValueObject\Reporting\FileDiff; use Rector\Parallel\Command\WorkerCommandLineFactory; use Rector\Parallel\ValueObject\Bridge; @@ -50,14 +52,13 @@ public function __construct( /** * @param callable(int $stepCount): void $postFileCallback Used for progress bar jump - * @return array{file_diffs: FileDiff[], system_errors: SystemError[], system_errors_count: int} */ public function process( Schedule $schedule, string $mainScript, callable $postFileCallback, InputInterface $input - ): array { + ): ProcessResult { $jobs = array_reverse($schedule->getJobs()); $streamSelectLoop = new StreamSelectLoop(); @@ -65,7 +66,13 @@ public function process( $numberOfProcesses = $schedule->getNumberOfProcesses(); // initial counters + + /** @var FileDiff[] $fileDiffs */ $fileDiffs = []; + + /** @var CollectedData[] $collectedDatas */ + $collectedDatas = []; + /** @var SystemError[] $systemErrors */ $systemErrors = []; @@ -106,7 +113,6 @@ public function process( $serverPort = parse_url($serverAddress, PHP_URL_PORT); $systemErrorsCount = 0; - $reachedSystemErrorsCountLimit = false; $handleErrorCallable = function (Throwable $throwable) use ( @@ -159,6 +165,7 @@ function (array $json) use ( &$jobs, $postFileCallback, &$systemErrorsCount, + &$collectedDatas, &$reachedInternalErrorsCountLimit, $processIdentifier ): void { @@ -176,6 +183,10 @@ function (array $json) use ( $fileDiffs[] = FileDiff::decode($jsonFileDiff); } + foreach ($json[Bridge::COLLECTED_DATA] as $jsonCollectedData) { + $collectedDatas[] = CollectedData::decode($jsonCollectedData); + } + $postFileCallback($json[Bridge::FILES_COUNT]); $systemErrorsCount += $json[Bridge::SYSTEM_ERRORS_COUNT]; @@ -226,10 +237,6 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v )); } - return [ - Bridge::FILE_DIFFS => $fileDiffs, - Bridge::SYSTEM_ERRORS => $systemErrors, - Bridge::SYSTEM_ERRORS_COUNT => count($systemErrors), - ]; + return new ProcessResult($systemErrors, $fileDiffs, $collectedDatas); } } diff --git a/packages/Parallel/ValueObject/Bridge.php b/packages/Parallel/ValueObject/Bridge.php index bc51e88a272..a56cb649c85 100644 --- a/packages/Parallel/ValueObject/Bridge.php +++ b/packages/Parallel/ValueObject/Bridge.php @@ -33,4 +33,9 @@ final class Bridge * @var string */ public const FILES_COUNT = 'files_count'; + + /** + * @var string + */ + public const COLLECTED_DATA = 'collected_data'; } diff --git a/packages/Parallel/WorkerRunner.php b/packages/Parallel/WorkerRunner.php index 9886ed47e39..a29f988bd34 100644 --- a/packages/Parallel/WorkerRunner.php +++ b/packages/Parallel/WorkerRunner.php @@ -59,7 +59,8 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura /** @var string[] $filePaths */ $filePaths = $json[Bridge::FILES] ?? []; - $systemErrorsAndFileDiffs = $this->applicationFileProcessor->processFiles($filePaths, $configuration); + + $processResult = $this->applicationFileProcessor->processFiles($filePaths, $configuration); /** * this invokes all listeners listening $decoder->on(...) @see \Symplify\EasyParallel\Enum\ReactEvent::DATA @@ -67,10 +68,11 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura $encoder->write([ ReactCommand::ACTION => Action::RESULT, self::RESULT => [ - Bridge::FILE_DIFFS => $systemErrorsAndFileDiffs[Bridge::FILE_DIFFS], + Bridge::FILE_DIFFS => $processResult->getFileDiffs(), Bridge::FILES_COUNT => count($filePaths), - Bridge::SYSTEM_ERRORS => $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS], - Bridge::SYSTEM_ERRORS_COUNT => $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS_COUNT], + Bridge::SYSTEM_ERRORS => $processResult->getSystemErrors(), + Bridge::SYSTEM_ERRORS_COUNT => count($processResult->getSystemErrors()), + Bridge::COLLECTED_DATA => $processResult->getCollectedData(), ], ]); }); diff --git a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php index a1659322953..399db364304 100644 --- a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php +++ b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php @@ -145,7 +145,7 @@ private function shouldSkip(Class_ $class): bool if ($this->nodeNameResolver->isStringName($className, $transformOnNamespace)) { continue; } - + if (! $this->nodeNameResolver->matchesStringName($className, $transformOnNamespace)) { return true; } diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index 303b6f16fec..f6d3235facf 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -5,6 +5,7 @@ namespace Rector\Core\Application; use Nette\Utils\FileSystem as UtilsFileSystem; +use PHPStan\Collectors\CollectedData; use Rector\Caching\Detector\ChangedFilesDetector; use Rector\Core\Application\FileProcessor\PhpFileProcessor; use Rector\Core\Configuration\Option; @@ -14,10 +15,11 @@ use Rector\Core\ValueObject\Application\File; use Rector\Core\ValueObject\Configuration; use Rector\Core\ValueObject\Error\SystemError; +use Rector\Core\ValueObject\FileProcessResult; +use Rector\Core\ValueObject\ProcessResult; use Rector\Core\ValueObject\Reporting\FileDiff; use Rector\Core\ValueObjectFactory\Application\FileFactory; use Rector\Parallel\Application\ParallelFileProcessor; -use Rector\Parallel\ValueObject\Bridge; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -41,54 +43,44 @@ final class ApplicationFileProcessor public function __construct( private readonly SymfonyStyle $symfonyStyle, private readonly FileFactory $fileFactory, - private readonly ArrayParametersMerger $arrayParametersMerger, private readonly ParallelFileProcessor $parallelFileProcessor, private readonly ScheduleFactory $scheduleFactory, private readonly CpuCoreCountProvider $cpuCoreCountProvider, private readonly ChangedFilesDetector $changedFilesDetector, private readonly CurrentFileProvider $currentFileProvider, private readonly PhpFileProcessor $phpFileProcessor, + private readonly ArrayParametersMerger $arrayParametersMerger, ) { } - /** - * @return array{system_errors: SystemError[], file_diffs: FileDiff[]} - */ - public function run(Configuration $configuration, InputInterface $input): array + public function run(Configuration $configuration, InputInterface $input): ProcessResult { $filePaths = $this->fileFactory->findFilesInPaths($configuration->getPaths(), $configuration); // no files found if ($filePaths === []) { - return [ - Bridge::SYSTEM_ERRORS => [], - Bridge::FILE_DIFFS => [], - ]; + return new ProcessResult([], [], []); } $this->configureCustomErrorHandler(); if ($configuration->isParallel()) { - $systemErrorsAndFileDiffs = $this->runParallel($filePaths, $configuration, $input); + $processResult = $this->runParallel($filePaths, $configuration, $input); } else { - $systemErrorsAndFileDiffs = $this->processFiles($filePaths, $configuration, false); + $processResult = $this->processFiles($filePaths, $configuration, false); } - $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS] = array_merge( - $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS], - $this->systemErrors - ); + $processResult->addSystemErrors($this->systemErrors); $this->restoreErrorHandler(); - return $systemErrorsAndFileDiffs; + return $processResult; } /** * @param string[] $filePaths - * @return array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} */ - public function processFiles(array $filePaths, Configuration $configuration, bool $isParallel = true): array + public function processFiles(array $filePaths, Configuration $configuration, bool $isParallel = true): ProcessResult { $shouldShowProgressBar = $configuration->shouldShowProgressBar(); @@ -99,17 +91,32 @@ public function processFiles(array $filePaths, Configuration $configuration, boo $this->symfonyStyle->progressAdvance(0); } - $systemErrorsAndFileDiffs = [ - Bridge::SYSTEM_ERRORS => [], - Bridge::FILE_DIFFS => [], - Bridge::SYSTEM_ERRORS_COUNT => 0, - ]; + /** @var SystemError[] $systemErrors */ + $systemErrors = []; + + /** @var FileDiff[] $fileDiffs */ + $fileDiffs = []; + + /** @var CollectedData[] $collectedData */ + $collectedData = []; foreach ($filePaths as $filePath) { $file = new File($filePath, UtilsFileSystem::read($filePath)); try { - $systemErrorsAndFileDiffs = $this->processFile($file, $systemErrorsAndFileDiffs, $configuration); + $fileProcessResult = $this->processFile($file, $configuration); + + $systemErrors = $this->arrayParametersMerger->merge( + $systemErrors, + $fileProcessResult->getSystemErrors() + ); + + $currentFileDiff = $fileProcessResult->getFileDiff(); + if ($currentFileDiff instanceof FileDiff) { + $fileDiffs[] = $currentFileDiff; + } + + $collectedData = array_merge($collectedData, $fileProcessResult->getCollectedData()); // progress bar +1, // progress bar on parallel handled on runParallel() @@ -123,35 +130,26 @@ public function processFiles(array $filePaths, Configuration $configuration, boo throw $throwable; } - $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS][] = $this->resolveSystemError($throwable, $filePath); + $systemErrors[] = $this->resolveSystemError($throwable, $filePath); } } - return $systemErrorsAndFileDiffs; + return new ProcessResult($systemErrors, $fileDiffs, $collectedData); } - /** - * @param array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} $systemErrorsAndFileDiffs - * @return array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} - */ - private function processFile(File $file, array $systemErrorsAndFileDiffs, Configuration $configuration): array + private function processFile(File $file, Configuration $configuration): FileProcessResult { $this->currentFileProvider->setFile($file); - $phpSystemErrorsAndFileDiffs = $this->phpFileProcessor->process($file, $configuration); - - $systemErrorsAndFileDiffs = $this->arrayParametersMerger->merge( - $systemErrorsAndFileDiffs, - $phpSystemErrorsAndFileDiffs - ); + $fileProcessResult = $this->phpFileProcessor->process($file, $configuration); - if ($systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS] !== []) { + if ($fileProcessResult->getSystemErrors() !== []) { $this->changedFilesDetector->invalidateFile($file->getFilePath()); - } elseif (! $configuration->isDryRun() || $systemErrorsAndFileDiffs[Bridge::FILE_DIFFS] === []) { + } elseif (! $configuration->isDryRun() || ! $fileProcessResult->getFileDiff() instanceof FileDiff) { $this->changedFilesDetector->cacheFile($file->getFilePath()); } - return $systemErrorsAndFileDiffs; + return $fileProcessResult; } private function resolveSystemError(Throwable $throwable, string $filePath): SystemError @@ -198,9 +196,8 @@ private function restoreErrorHandler(): void /** * @param string[] $filePaths - * @return array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} */ - private function runParallel(array $filePaths, Configuration $configuration, InputInterface $input): array + private function runParallel(array $filePaths, Configuration $configuration, InputInterface $input): ProcessResult { $schedule = $this->scheduleFactory->create( $this->cpuCoreCountProvider->provide(), @@ -209,9 +206,6 @@ private function runParallel(array $filePaths, Configuration $configuration, Inp $filePaths ); - $postFileCallback = static function (int $stepCount): void { - }; - if ($configuration->shouldShowProgressBar()) { $fileCount = count($filePaths); $this->symfonyStyle->progressStart($fileCount); @@ -221,6 +215,9 @@ private function runParallel(array $filePaths, Configuration $configuration, Inp $this->symfonyStyle->progressAdvance($stepCount); // running in parallel here → nothing else to do }; + } else { + $postFileCallback = static function (int $stepCount): void { + }; } $mainScript = $this->resolveCalledRectorBinary(); diff --git a/src/Application/FileProcessor/PhpFileProcessor.php b/src/Application/FileProcessor/PhpFileProcessor.php index 5ba5bb4cb02..17f1792ebb1 100644 --- a/src/Application/FileProcessor/PhpFileProcessor.php +++ b/src/Application/FileProcessor/PhpFileProcessor.php @@ -16,8 +16,8 @@ use Rector\Core\ValueObject\Application\File; use Rector\Core\ValueObject\Configuration; use Rector\Core\ValueObject\Error\SystemError; +use Rector\Core\ValueObject\FileProcessResult; use Rector\Core\ValueObject\Reporting\FileDiff; -use Rector\Parallel\ValueObject\Bridge; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; use Symfony\Component\Console\Style\SymfonyStyle; use Throwable; @@ -41,23 +41,13 @@ public function __construct( ) { } - /** - * @return array{system_errors: SystemError[], file_diffs: FileDiff[]} - */ - public function process(File $file, Configuration $configuration): array + public function process(File $file, Configuration $configuration): FileProcessResult { - $systemErrorsAndFileDiffs = [ - Bridge::SYSTEM_ERRORS => [], - Bridge::FILE_DIFFS => [], - ]; - // 1. parse files to nodes - $parsingSystemErrors = $this->parseFileAndDecorateNodes($file); - if ($parsingSystemErrors !== []) { + $parsingSystemError = $this->parseFileAndDecorateNodes($file); + if ($parsingSystemError instanceof SystemError) { // we cannot process this file as the parsing and type resolving itself went wrong - $systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS] = $parsingSystemErrors; - - return $systemErrorsAndFileDiffs; + return new FileProcessResult([$parsingSystemError], null, []); } $fileHasChanged = false; @@ -88,30 +78,19 @@ public function process(File $file, Configuration $configuration): array } if ($configuration->shouldShowDiffs() && $rectorWithLineChanges !== null) { - $file->setFileDiff( - $this->fileDiffFactory->createFileDiffWithLineChanges( - $file, - $file->getOriginalFileContent(), - $file->getFileContent(), - $rectorWithLineChanges - ) + $currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges( + $file, + $file->getOriginalFileContent(), + $file->getFileContent(), + $rectorWithLineChanges ); + $file->setFileDiff($currentFileDiff); } - // return json here - $fileDiff = $file->getFileDiff(); - if (! $fileDiff instanceof FileDiff) { - return $systemErrorsAndFileDiffs; - } - - $systemErrorsAndFileDiffs[Bridge::FILE_DIFFS] = [$fileDiff]; - return $systemErrorsAndFileDiffs; + return new FileProcessResult([], $file->getFileDiff(), []); } - /** - * @return SystemError[] - */ - private function parseFileAndDecorateNodes(File $file): array + private function parseFileAndDecorateNodes(File $file): ?SystemError { $this->notifyFile($file); @@ -125,23 +104,18 @@ private function parseFileAndDecorateNodes(File $file): array throw $analysedCodeException; } - $autoloadSystemError = $this->errorFactory->createAutoloadError( - $analysedCodeException, - $file->getFilePath() - ); - return [$autoloadSystemError]; + return $this->errorFactory->createAutoloadError($analysedCodeException, $file->getFilePath()); } catch (Throwable $throwable) { if ($this->symfonyStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) { throw $throwable; } $relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath()); - $systemError = new SystemError($throwable->getMessage(), $relativeFilePath, $throwable->getLine()); - return [$systemError]; + return new SystemError($throwable->getMessage(), $relativeFilePath, $throwable->getLine()); } - return []; + return null; } private function printFile(File $file, Configuration $configuration): void diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 7fbaca36836..2067d4ce1d0 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -19,7 +19,6 @@ use Rector\Core\Util\MemoryLimiter; use Rector\Core\ValueObject\Configuration; use Rector\Core\ValueObject\ProcessResult; -use Rector\Core\ValueObjectFactory\ProcessResultFactory; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -33,11 +32,10 @@ public function __construct( private readonly ChangedFilesDetector $changedFilesDetector, private readonly ConfigInitializer $configInitializer, private readonly ApplicationFileProcessor $applicationFileProcessor, - private readonly ProcessResultFactory $processResultFactory, private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, - private readonly OutputFormatterCollector $outputFormatterCollector, - private readonly SymfonyStyle $symfonyStyle, - private readonly MemoryLimiter $memoryLimiter, + private readonly OutputFormatterCollector $outputFormatterCollector, + private readonly SymfonyStyle $symfonyStyle, + private readonly MemoryLimiter $memoryLimiter, private readonly ConfigurationFactory $configurationFactory, ) { parent::__construct(); @@ -83,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // MAIN PHASE // 2. run Rector - $systemErrorsAndFileDiffs = $this->applicationFileProcessor->run($configuration, $input); + $processResult = $this->applicationFileProcessor->run($configuration, $input); // REPORTING PHASE // 3. reporting phase @@ -91,7 +89,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $outputFormat = $configuration->getOutputFormat(); $outputFormatter = $this->outputFormatterCollector->getByName($outputFormat); - $processResult = $this->processResultFactory->create($systemErrorsAndFileDiffs); $outputFormatter->report($processResult, $configuration); return $this->resolveReturnCode($processResult, $configuration); @@ -122,7 +119,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v private function resolveReturnCode(ProcessResult $processResult, Configuration $configuration): int { // some system errors were found → fail - if ($processResult->getErrors() !== []) { + if ($processResult->getSystemErrors() !== []) { return ExitCode::FAILURE; } diff --git a/src/ValueObject/FileProcessResult.php b/src/ValueObject/FileProcessResult.php new file mode 100644 index 00000000000..f3a05d29af0 --- /dev/null +++ b/src/ValueObject/FileProcessResult.php @@ -0,0 +1,44 @@ +systemErrors; + } + + public function getFileDiff(): ?FileDiff + { + return $this->fileDiff; + } + + /** + * @return CollectedData[] + */ + public function getCollectedData(): array + { + return $this->collectedData; + } +} diff --git a/src/ValueObject/ProcessResult.php b/src/ValueObject/ProcessResult.php index 6cc8617a0e5..9089b90b157 100644 --- a/src/ValueObject/ProcessResult.php +++ b/src/ValueObject/ProcessResult.php @@ -4,25 +4,34 @@ namespace Rector\Core\ValueObject; +use PHPStan\Collectors\CollectedData; use Rector\Core\ValueObject\Error\SystemError; use Rector\Core\ValueObject\Reporting\FileDiff; use Webmozart\Assert\Assert; -/** - * @see \Rector\Core\ValueObjectFactory\ProcessResultFactory - */ final class ProcessResult { /** - * @param FileDiff[] $fileDiffs * @param SystemError[] $systemErrors + * @param FileDiff[] $fileDiffs + * @param CollectedData[] $collectedData */ public function __construct( - private readonly array $systemErrors, + private array $systemErrors, private readonly array $fileDiffs, + private readonly array $collectedData ) { - Assert::allIsAOf($fileDiffs, FileDiff::class); - Assert::allIsAOf($systemErrors, SystemError::class); + Assert::allIsInstanceOf($systemErrors, SystemError::class); + Assert::allIsInstanceOf($fileDiffs, FileDiff::class); + Assert::allIsInstanceOf($collectedData, CollectedData::class); + } + + /** + * @return SystemError[] + */ + public function getSystemErrors(): array + { + return $this->systemErrors; } /** @@ -34,10 +43,20 @@ public function getFileDiffs(): array } /** - * @return SystemError[] + * @return CollectedData[] */ - public function getErrors(): array + public function getCollectedData(): array { - return $this->systemErrors; + return $this->collectedData; + } + + /** + * @param SystemError[] $systemErrors + */ + public function addSystemErrors(array $systemErrors): void + { + Assert::allIsInstanceOf($systemErrors, SystemError::class); + + $this->systemErrors = array_merge($this->systemErrors, $systemErrors); } } diff --git a/src/ValueObjectFactory/ProcessResultFactory.php b/src/ValueObjectFactory/ProcessResultFactory.php deleted file mode 100644 index 14b38e1b9ae..00000000000 --- a/src/ValueObjectFactory/ProcessResultFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -