Skip to content

Commit

Permalink
Updated Rector to commit 184ce766abb6bdca8d590c757479a67a915251f8
Browse files Browse the repository at this point in the history
rectorphp/rector-src@184ce76 [FileProcessor] Remove unnecessary FileDiffFactory::createTempFileDiff() take 2 (#6528)
  • Loading branch information
TomasVotruba committed Dec 12, 2024
1 parent 6e4ecfe commit 3ce90db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
28 changes: 14 additions & 14 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 2 additions & 6 deletions src/ChangesReporting/ValueObjectFactory/FileDiffFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 0 additions & 3 deletions src/Differ/DefaultDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3ce90db

Please sign in to comment.