Skip to content

Commit fdbb6f1

Browse files
Remove infinite-loop guard from FileProcessor (#8811)
* Remove infinite-loop guard from FileProcessor Infinite loop is happen when files keep changing, not that original content equal to new file content. I think this can be removed as not working as expected. * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent 8733317 commit fdbb6f1

1 file changed

Lines changed: 0 additions & 37 deletions

File tree

‎src/Application/FileProcessor.php‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ public function processFile(File $file, Configuration $configuration): FileProce
5959
$fileHasChanged = false;
6060
$filePath = $file->getFilePath();
6161

62-
// infinite-loop guard: remember every file content the loop produces; a rule set that
63-
// keeps flipping the file between states would never settle, so once a content repeats
64-
// we stop and report instead of looping forever
65-
$seenContentHashes = [
66-
hash('xxh128', $file->getOriginalFileContent()) => true,
67-
];
68-
6962
do {
7063
$file->changeHasChanged(false);
7164

@@ -88,15 +81,6 @@ public function processFile(File $file, Configuration $configuration): FileProce
8881
}
8982

9083
$fileHasChanged = true;
91-
92-
// this exact content was already produced in an earlier pass: the rules cycle
93-
// and will never converge, so stop here
94-
$contentHash = hash('xxh128', $file->getFileContent());
95-
if (isset($seenContentHashes[$contentHash])) {
96-
return $this->createNotConvergingResult($file, $fileHasChanged);
97-
}
98-
99-
$seenContentHashes[$contentHash] = true;
10084
} while (true);
10185

10286
// 5. add as cacheable if not changed at all
@@ -124,27 +108,6 @@ public function processFile(File $file, Configuration $configuration): FileProce
124108
return new FileProcessResult([], $file->getFileDiff(), $file->hasChanged());
125109
}
126110

127-
private function createNotConvergingResult(File $file, bool $fileHasChanged): FileProcessResult
128-
{
129-
$rectorClasses = [];
130-
foreach ($file->getRectorWithLineChanges() as $rectorWithLineChange) {
131-
$rectorClasses[$rectorWithLineChange->getRectorClass()] = true;
132-
}
133-
134-
$message = sprintf(
135-
'File did not stabilize, the rules keep flipping it between states. Rules applied: %s',
136-
implode(', ', array_keys($rectorClasses))
137-
);
138-
139-
// in tests a non-converging file is a rule bug that must surface, not a silent partial result
140-
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
141-
throw new ShouldNotHappenException($message . ' in ' . $file->getFilePath());
142-
}
143-
144-
$systemError = new SystemError($message, $this->filePathHelper->relativePath($file->getFilePath()));
145-
return new FileProcessResult([$systemError], $file->getFileDiff(), $fileHasChanged);
146-
}
147-
148111
private function parseFileAndDecorateNodes(File $file): ?SystemError
149112
{
150113
try {

0 commit comments

Comments
 (0)