diff --git a/src/Application/FileProcessor.php b/src/Application/FileProcessor.php index 7c3a404ead0..317f863aabd 100644 --- a/src/Application/FileProcessor.php +++ b/src/Application/FileProcessor.php @@ -89,31 +89,31 @@ public function processFile(File $file, Configuration $configuration) : FileProc } $fileHasChanged = \false; $filePath = $file->getFilePath(); - // 2. change nodes with Rectors - $rectorWithLineChanges = null; do { $file->changeHasChanged(\false); + // 1. change nodes with Rector Rules $newStmts = $this->rectorNodeTraverser->traverse($file->getNewStmts()); - // apply post rectors + // 2. apply post rectors $postNewStmts = $this->postFileProcessor->traverse($newStmts, $file); - // this is needed for new tokens added in "afterTraverse()" + // 3. this is needed for new tokens added in "afterTraverse()" $file->changeNewStmts($postNewStmts); - // 3. print to file or string + // 4. print to file or string // important to detect if file has changed $this->printFile($file, $configuration, $filePath); - $fileHasChangedInCurrentPass = $file->hasChanged(); - if ($fileHasChangedInCurrentPass) { - $file->setFileDiff($this->fileDiffFactory->createTempFileDiff($file)); - $rectorWithLineChanges = $file->getRectorWithLineChanges(); - $fileHasChanged = \true; + // no change in current iteration, stop + if (!$file->hasChanged()) { + break; } - } while ($fileHasChangedInCurrentPass); + $fileHasChanged = \true; + } while (\true); // 5. add as cacheable if not changed at all if (!$fileHasChanged) { $this->changedFilesDetector->addCachableFile($filePath); - } - if ($configuration->shouldShowDiffs() && $rectorWithLineChanges !== null) { - $currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges($file, $file->getOriginalFileContent(), $file->getFileContent(), $rectorWithLineChanges); + } else { + // when changed, set final status changed to true + // to ensure it make sense to verify in next process when needed + $file->changeHasChanged(\true); + $currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges($configuration->shouldShowDiffs(), $file, $file->getOriginalFileContent(), $file->getFileContent(), $file->getRectorWithLineChanges()); $file->setFileDiff($currentFileDiff); } return new FileProcessResult([], $file->getFileDiff()); diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 341f7576367..4303459441a 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '0bfd08d038d2932ff6efb6a210a8985ac6364afa'; + public const PACKAGE_VERSION = '184ce766abb6bdca8d590c757479a67a915251f8'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-12 16:24:52'; + public const RELEASE_DATE = '2024-12-12 10:33:44'; /** * @var int */ diff --git a/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php b/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php index ce6f1d93aa2..148dc86c843 100644 --- a/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php +++ b/src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php @@ -32,14 +32,10 @@ public function __construct(DefaultDiffer $defaultDiffer, ConsoleDiffer $console /** * @param RectorWithLineChange[] $rectorsWithLineChanges */ - public function createFileDiffWithLineChanges(File $file, string $oldContent, string $newContent, array $rectorsWithLineChanges) : FileDiff + public function createFileDiffWithLineChanges(bool $shouldShowDiffs, File $file, string $oldContent, string $newContent, array $rectorsWithLineChanges) : FileDiff { $relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath()); // always keep the most recent diff - return new FileDiff($relativeFilePath, $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $rectorsWithLineChanges); - } - public function createTempFileDiff(File $file) : FileDiff - { - return $this->createFileDiffWithLineChanges($file, '', '', $file->getRectorWithLineChanges()); + return new FileDiff($relativeFilePath, $shouldShowDiffs ? $this->defaultDiffer->diff($oldContent, $newContent) : '', $shouldShowDiffs ? $this->consoleDiffer->diff($oldContent, $newContent) : '', $rectorsWithLineChanges); } } diff --git a/src/Differ/DefaultDiffer.php b/src/Differ/DefaultDiffer.php index 0c10b1775b0..d598274d1ab 100644 --- a/src/Differ/DefaultDiffer.php +++ b/src/Differ/DefaultDiffer.php @@ -18,9 +18,6 @@ public function __construct() } public function diff(string $old, string $new) : string { - if ($old === $new) { - return ''; - } return $this->differ->diff($old, $new); } }