// the find
sebastianbergmann/diff
Diff implementation
A PHP diff library factored out of PHPUnit, implementing Myers diff algorithm with multiple output formats (unified, strict unified, diff-only) and a parser for consuming existing unified diffs. It's a focused utility for anyone needing programmatic diff generation or parsing in PHP — most users will encounter it as a PHPUnit transitive dependency without realising it.
Myers diff implementation is solid and well-tested — the test suite includes integration tests that validate output against fixtures, not just unit tests against mocked internals. The output builder pattern is genuinely well-designed: swapping in StrictUnifiedDiffOutputBuilder gets you patch/git-apply compatible output, and implementing DiffOutputBuilderInterface is straightforward if the three built-in builders don't cover your case. Maintained by Sebastian Bergmann who keeps it on a tight release cadence — last push was two days ago. PHPStan at strict rules plus ergebnis/phpstan-rules means the codebase is typed through and the static analysis bar is high.
The Parser only handles unified diff format — if you're dealing with context diffs or git's extended headers (rename detection, mode changes, binary patches), you're writing your own. The off-by-one documented in the README for zero-range chunks is a genuine footgun: 'the line number after which the chunk should be inserted' only for size-0 hunks is not intuitive and will burn you the first time you build a UI on top of the parsed output. No streaming support — everything is string-in/string-out, so diffing large files loads them entirely into memory. With 87 forks against 7.6k stars, the community contribution surface is basically nonexistent, which means bugs you find are bugs you'll probably fix yourself.