diff(file_get_contents($oldFilePath), file_get_contents($newFilePath)); if ($stringDiff === '') { continue; } $isDifferent = true; echo "$path:\n"; $startLine = 1; $startContext = 1; foreach (explode("\n", $stringDiff) as $i => $line) { $matches = Strings::match($line, '/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/'); if ($matches !== null) { $startLine = (int) $matches[1]; $startContext = (int) $matches[2]; continue; } if ($lineNumber < $startLine || $lineNumber > ($startLine + $startContext)) { continue; } if (str_starts_with($line, '+')) { echo "\033[32m$line\033[0m\n"; } elseif (str_starts_with($line, '-')) { echo "\033[31m$line\033[0m\n"; } else { echo "$line\n"; } } echo "\n"; } if ($isDifferent) { exit(1); }