{"id":37004099,"url":"https://github.com/ezsystems/diff","last_synced_at":"2026-01-14T00:36:38.748Z","repository":{"id":45393017,"uuid":"247804661","full_name":"ezsystems/diff","owner":"ezsystems","description":"Diff implementation","archived":false,"fork":true,"pushed_at":"2022-01-18T14:34:07.000Z","size":3067,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T09:52:08.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sebastianbergmann/diff","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ezsystems.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-16T19:55:32.000Z","updated_at":"2025-02-15T00:47:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ezsystems/diff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ezsystems/diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezsystems%2Fdiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezsystems%2Fdiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezsystems%2Fdiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezsystems%2Fdiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezsystems","download_url":"https://codeload.github.com/ezsystems/diff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezsystems%2Fdiff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T00:36:38.115Z","updated_at":"2026-01-14T00:36:38.733Z","avatar_url":"https://github.com/ezsystems.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sebastian/diff\n\n[![CI Status](https://github.com/sebastianbergmann/diff/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/diff/actions)\n[![Type Coverage](https://shepherd.dev/github/sebastianbergmann/diff/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/diff)\n\nDiff implementation for PHP, factored out of PHPUnit into a stand-alone component.\n\n## Installation\n\nYou can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):\n\n```\ncomposer require sebastian/diff\n```\n\nIf you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:\n\n```\ncomposer require --dev sebastian/diff\n```\n\n### Usage\n\n#### Generating diff\n\nThe `Differ` class can be used to generate a textual representation of the difference between two strings:\n\n```php\n\u003c?php\nuse SebastianBergmann\\Diff\\Differ;\n\n$differ = new Differ;\nprint $differ-\u003ediff('foo', 'bar');\n```\n\nThe code above yields the output below:\n```diff\n--- Original\n+++ New\n@@ @@\n-foo\n+bar\n```\n\nThere are three output builders available in this package:\n\n#### UnifiedDiffOutputBuilder\n\nThis is default builder, which generates the output close to udiff and is used by PHPUnit.\n\n```php\n\u003c?php\n\nuse SebastianBergmann\\Diff\\Differ;\nuse SebastianBergmann\\Diff\\Output\\UnifiedDiffOutputBuilder;\n\n$builder = new UnifiedDiffOutputBuilder(\n    \"--- Original\\n+++ New\\n\", // custom header\n    false                      // do not add line numbers to the diff \n);\n\n$differ = new Differ($builder);\nprint $differ-\u003ediff('foo', 'bar');\n```\n\n#### StrictUnifiedDiffOutputBuilder\n\nGenerates (strict) Unified diff's (unidiffs) with hunks,\nsimilar to `diff -u` and compatible with `patch` and `git apply`.\n\n```php\n\u003c?php\n\nuse SebastianBergmann\\Diff\\Differ;\nuse SebastianBergmann\\Diff\\Output\\StrictUnifiedDiffOutputBuilder;\n\n$builder = new StrictUnifiedDiffOutputBuilder([\n    'collapseRanges'      =\u003e true, // ranges of length one are rendered with the trailing `,1`\n    'commonLineThreshold' =\u003e 6,    // number of same lines before ending a new hunk and creating a new one (if needed)\n    'contextLines'        =\u003e 3,    // like `diff:  -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3\n    'fromFile'            =\u003e null,\n    'fromFileDate'        =\u003e null,\n    'toFile'              =\u003e null,\n    'toFileDate'          =\u003e null,\n]);\n\n$differ = new Differ($builder);\nprint $differ-\u003ediff('foo', 'bar');\n```\n\n#### DiffOnlyOutputBuilder\n\nOutput only the lines that differ.\n\n```php\n\u003c?php\n\nuse SebastianBergmann\\Diff\\Differ;\nuse SebastianBergmann\\Diff\\Output\\DiffOnlyOutputBuilder;\n\n$builder = new DiffOnlyOutputBuilder(\n    \"--- Original\\n+++ New\\n\"\n);\n\n$differ = new Differ($builder);\nprint $differ-\u003ediff('foo', 'bar');\n```\n\n#### DiffOutputBuilderInterface\n\nYou can pass any output builder to the `Differ` class as longs as it implements the `DiffOutputBuilderInterface`.\n\n#### Parsing diff\n\nThe `Parser` class can be used to parse a unified diff into an object graph:\n\n```php\nuse SebastianBergmann\\Diff\\Parser;\nuse SebastianBergmann\\Git;\n\n$git = new Git('/usr/local/src/money');\n\n$diff = $git-\u003egetDiff(\n  '948a1a07768d8edd10dcefa8315c1cbeffb31833',\n  'c07a373d2399f3e686234c4f7f088d635eb9641b'\n);\n\n$parser = new Parser;\n\nprint_r($parser-\u003eparse($diff));\n```\n\nThe code above yields the output below:\n\n    Array\n    (\n        [0] =\u003e SebastianBergmann\\Diff\\Diff Object\n            (\n                [from:SebastianBergmann\\Diff\\Diff:private] =\u003e a/tests/MoneyTest.php\n                [to:SebastianBergmann\\Diff\\Diff:private] =\u003e b/tests/MoneyTest.php\n                [chunks:SebastianBergmann\\Diff\\Diff:private] =\u003e Array\n                    (\n                        [0] =\u003e SebastianBergmann\\Diff\\Chunk Object\n                            (\n                                [start:SebastianBergmann\\Diff\\Chunk:private] =\u003e 87\n                                [startRange:SebastianBergmann\\Diff\\Chunk:private] =\u003e 7\n                                [end:SebastianBergmann\\Diff\\Chunk:private] =\u003e 87\n                                [endRange:SebastianBergmann\\Diff\\Chunk:private] =\u003e 7\n                                [lines:SebastianBergmann\\Diff\\Chunk:private] =\u003e Array\n                                    (\n                                        [0] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e      * @covers SebastianBergmann\\Money\\Money::add\n                                            )\n\n                                        [1] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e      * @covers SebastianBergmann\\Money\\Money::newMoney\n                                            )\n\n                                        [2] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e      */\n                                            )\n\n                                        [3] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 2\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e     public function testAnotherMoneyWithSameCurrencyObjectCanBeAdded()\n                                            )\n\n                                        [4] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 1\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e     public function testAnotherMoneyObjectWithSameCurrencyCanBeAdded()\n                                            )\n\n                                        [5] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e     {\n                                            )\n\n                                        [6] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e         $a = new Money(1, new Currency('EUR'));\n                                            )\n\n                                        [7] =\u003e SebastianBergmann\\Diff\\Line Object\n                                            (\n                                                [type:SebastianBergmann\\Diff\\Line:private] =\u003e 3\n                                                [content:SebastianBergmann\\Diff\\Line:private] =\u003e         $b = new Money(2, new Currency('EUR'));\n                                            )\n                                    )\n                            )\n                    )\n            )\n    )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezsystems%2Fdiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezsystems%2Fdiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezsystems%2Fdiff/lists"}