{"id":13462139,"url":"https://github.com/sebastianbergmann/diff","last_synced_at":"2026-02-06T06:11:21.238Z","repository":{"id":6905171,"uuid":"8155345","full_name":"sebastianbergmann/diff","owner":"sebastianbergmann","description":"Diff implementation","archived":false,"fork":false,"pushed_at":"2026-01-01T08:51:07.000Z","size":55633,"stargazers_count":7661,"open_issues_count":8,"forks_count":86,"subscribers_count":26,"default_branch":"main","last_synced_at":"2026-02-02T08:51:43.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastianbergmann.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"sebastianbergmann","liberapay":"sebastianbergmann","thanks_dev":"u/gh/sebastianbergmann","tidelift":"packagist/sebastian/diff"}},"created_at":"2013-02-12T08:34:51.000Z","updated_at":"2026-01-28T10:55:00.000Z","dependencies_parsed_at":"2023-01-16T19:15:54.666Z","dependency_job_id":"d7504775-f072-4354-878e-6cd1a5027260","html_url":"https://github.com/sebastianbergmann/diff","commit_stats":{"total_commits":524,"total_committers":27,"mean_commits":19.40740740740741,"dds":"0.19465648854961837","last_synced_commit":"1d7973beb55cc78c077c3bdcfac0e833104aa30f"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/sebastianbergmann/diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianbergmann%2Fdiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianbergmann%2Fdiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianbergmann%2Fdiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianbergmann%2Fdiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastianbergmann","download_url":"https://codeload.github.com/sebastianbergmann/diff/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianbergmann%2Fdiff/sbom","scorecard":{"id":808510,"data":{"date":"2025-08-11","repo":{"name":"github.com/sebastianbergmann/diff","commit":"98c299d8486b460efd667d0d64f1a32dd588971d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"checks":[{"name":"Maintained","score":4,"reason":"5 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-23T12:28:18.326Z","repository_id":6905171,"created_at":"2025-08-23T12:28:18.326Z","updated_at":"2025-08-23T12:28:18.326Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29153301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"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":"2024-07-31T12:00:39.895Z","updated_at":"2026-02-06T06:11:21.215Z","avatar_url":"https://github.com/sebastianbergmann.png","language":"PHP","funding_links":["https://github.com/sponsors/sebastianbergmann","https://liberapay.com/sebastianbergmann","https://thanks.dev/u/gh/sebastianbergmann","https://tidelift.com/funding/github/packagist/sebastian/diff"],"categories":["Uncategorized","PHP","目录","类库"],"sub_categories":["Uncategorized","代码分析 Code Analysis","未归类"],"readme":"[![Latest Stable Version](https://poser.pugx.org/sebastian/diff/v)](https://packagist.org/packages/sebastian/diff)\n[![CI Status](https://github.com/sebastianbergmann/diff/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/diff/actions)\n[![codecov](https://codecov.io/gh/sebastianbergmann/diff/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/diff)\n\n# sebastian/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 declare(strict_types=1);\nuse SebastianBergmann\\Diff\\Differ;\nuse SebastianBergmann\\Diff\\Output\\UnifiedDiffOutputBuilder;\n\n$differ = new Differ(new UnifiedDiffOutputBuilder);\n\nprint $differ-\u003ediff('foo', 'bar');\n```\n\nThe code above yields the output below:\n\n```diff\n--- Original\n+++ New\n@@ @@\n-foo\n+bar\n```\n\nThe `UnifiedDiffOutputBuilder` used in the example above generates output in \"unified diff\"\nformat and is used by PHPUnit, for example.\n\nThe `StrictUnifiedDiffOutputBuilder` generates output in \"strict unified diff\" format with\nhunks,  similar to `diff -u` and compatible with `patch` or `git apply`.\n\nThe `DiffOnlyOutputBuilder` generates output that only contains the lines that differ.\n\nIf none of these three output builders match your use case then you can implement\n`DiffOutputBuilderInterface` to generate custom output.\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\nNote: If the chunk size is 0 lines, i.e., `getStartRange()` or `getEndRange()` return 0, the number of line returned by `getStart()` or `getEnd()` is one lower than one would expect. It is the line number after which the chunk should be inserted or deleted; in all other cases, it gives the first line number of the replaced range of lines.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastianbergmann%2Fdiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastianbergmann%2Fdiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastianbergmann%2Fdiff/lists"}