{"id":19647323,"url":"https://github.com/ibexa/diff","last_synced_at":"2026-05-16T03:04:37.137Z","repository":{"id":45385138,"uuid":"353265023","full_name":"ibexa/diff","owner":"ibexa","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-16T09:37:36.000Z","size":3058,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-01-09T22:18:05.247Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibexa.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},"funding":{"github":"sebastianbergmann"}},"created_at":"2021-03-31T07:25:00.000Z","updated_at":"2024-10-10T07:08:48.000Z","dependencies_parsed_at":"2022-09-19T11:51:12.730Z","dependency_job_id":null,"html_url":"https://github.com/ibexa/diff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibexa%2Fdiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibexa%2Fdiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibexa%2Fdiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibexa%2Fdiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibexa","download_url":"https://codeload.github.com/ibexa/diff/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240954134,"owners_count":19884125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["hacktoberfest"],"created_at":"2024-11-11T14:43:25.026Z","updated_at":"2026-05-16T03:04:32.089Z","avatar_url":"https://github.com/ibexa.png","language":"PHP","funding_links":["https://github.com/sponsors/sebastianbergmann"],"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%2Fibexa%2Fdiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibexa%2Fdiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibexa%2Fdiff/lists"}