Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ public function processFile(File $file, Configuration $configuration): FileProce
$fileHasChanged = false;
$filePath = $file->getFilePath();

// infinite-loop guard: remember every file content the loop produces; a rule set that
// keeps flipping the file between states would never settle, so once a content repeats
// we stop and report instead of looping forever
$seenContentHashes = [
hash('xxh128', $file->getOriginalFileContent()) => true,
];

do {
$file->changeHasChanged(false);

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

$fileHasChanged = true;

// this exact content was already produced in an earlier pass: the rules cycle
// and will never converge, so stop here
$contentHash = hash('xxh128', $file->getFileContent());
if (isset($seenContentHashes[$contentHash])) {
return $this->createNotConvergingResult($file, $fileHasChanged);
}

$seenContentHashes[$contentHash] = true;
} while (true);

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

private function createNotConvergingResult(File $file, bool $fileHasChanged): FileProcessResult
{
$rectorClasses = [];
foreach ($file->getRectorWithLineChanges() as $rectorWithLineChange) {
$rectorClasses[$rectorWithLineChange->getRectorClass()] = true;
}

$message = sprintf(
'File did not stabilize, the rules keep flipping it between states. Rules applied: %s',
implode(', ', array_keys($rectorClasses))
);

// in tests a non-converging file is a rule bug that must surface, not a silent partial result
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw new ShouldNotHappenException($message . ' in ' . $file->getFilePath());
}

$systemError = new SystemError($message, $this->filePathHelper->relativePath($file->getFilePath()));
return new FileProcessResult([$systemError], $file->getFileDiff(), $fileHasChanged);
}

private function parseFileAndDecorateNodes(File $file): ?SystemError
{
try {
Expand Down
Loading