### Install sebastian/diff using Composer Source: https://github.com/sebastianbergmann/diff/blob/main/README.md Demonstrates how to add the sebastian/diff library to a project as a local or development-time dependency using Composer. ```bash composer require sebastian/diff composer require --dev sebastian/diff ``` -------------------------------- ### Additions to Foo.php Source: https://github.com/sebastianbergmann/diff/blob/main/tests/fixtures/patch2.txt This snippet shows the lines added to the Foo.php file, including new constants and a return statement within the doSomething method. ```php diff --git a/Foo.php b/Foo.php index abcdefg..abcdefh 100644 --- a/Foo.php +++ b/Foo.php @@ -20,4 +20,5 @@ class Foo const ONE = 1; const TWO = 2; + const THREE = 3; const FOUR = 4; @@ -320,4 +320,5 @@ class Foo const A = 'A'; const B = 'B'; + const C = 'C'; const D = 'D'; @@ -600,4 +600,5 @@ class Foo public function doSomething() { + return 'foo'; } ``` -------------------------------- ### Version History and Changes Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This section details the version history of the Diff component, highlighting the transition between major versions and specific patch releases. It also notes the removal of support for older PHP versions. ```markdown ### Removed * This component is no longer supported on PHP 5.6 [7.0.0]: https://github.com/sebastianbergmann/diff/compare/6.0...7.0.0 [6.0.2]: https://github.com/sebastianbergmann/diff/compare/6.0.1...6.0.2 [6.0.1]: https://github.com/sebastianbergmann/diff/compare/6.0.0...6.0.1 [6.0.0]: https://github.com/sebastianbergmann/diff/compare/5.1...6.0.0 [5.1.1]: https://github.com/sebastianbergmann/diff/compare/5.1.0...5.1.1 [5.1.0]: https://github.com/sebastianbergmann/diff/compare/5.0.3...5.1.0 [5.0.3]: https://github.com/sebastianbergmann/diff/compare/5.0.2...5.0.3 [5.0.2]: https://github.com/sebastianbergmann/diff/compare/5.0.1...5.0.2 [5.0.1]: https://github.com/sebastianbergmann/diff/compare/5.0.0...5.0.1 [5.0.0]: https://github.com/sebastianbergmann/diff/compare/4.0.4...5.0.0 [4.0.4]: https://github.com/sebastianbergmann/diff/compare/4.0.3...4.0.4 [4.0.3]: https://github.com/sebastianbergmann/diff/compare/4.0.2...4.0.3 [4.0.2]: https://github.com/sebastianbergmann/diff/compare/4.0.1...4.0.2 [4.0.1]: https://github.com/sebastianbergmann/diff/compare/4.0.0...4.0.1 [4.0.0]: https://github.com/sebastianbergmann/diff/compare/3.0.2...4.0.0 [3.0.2]: https://github.com/sebastianbergmann/diff/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/sebastianbergmann/diff/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/diff/compare/2.0...3.0.0 [2.0.1]: https://github.com/sebastianbergmann/diff/compare/c341c98ce083db77f896a0aa64f5ee7652915970...2.0.1 [2.0.0]: https://github.com/sebastianbergmann/diff/compare/1.4...c341c98ce083db77f896a0aa64f5ee7652915970 ``` -------------------------------- ### Diff Output Formats Source: https://github.com/sebastianbergmann/diff/blob/main/README.md Explains different output builders for generating diffs: `UnifiedDiffOutputBuilder` for standard unified diff, `StrictUnifiedDiffOutputBuilder` for strict unified diff compatible with `patch` or `git apply`, and `DiffOnlyOutputBuilder` for lines that differ. Also mentions the possibility of creating custom builders by implementing `DiffOutputBuilderInterface`. ```diff --- Original +++ New @@ @@ -foo +bar ``` -------------------------------- ### Generate Textual Diff Source: https://github.com/sebastianbergmann/diff/blob/main/README.md Shows how to use the `Differ` class to generate a textual representation of the difference between two strings using the `UnifiedDiffOutputBuilder`. ```php diff('foo', 'bar'); ``` -------------------------------- ### Parse Unified Diff Source: https://github.com/sebastianbergmann/diff/blob/main/README.md Demonstrates parsing a unified diff string obtained from Git into a structured object graph using the `SebastianBergmann\Diff\Parser` class. This involves initializing a Git object, fetching a diff between two commits, and then passing the diff content to the parser. ```php use SebastianBergmann\Diff\Parser; use SebastianBergmann\Git; $git = new Git('/usr/local/src/money'); $diff = $git->getDiff( '948a1a07768d8edd10dcefa8315c1cbeffb31833', 'c07a373d2399f3e686234c4f7f088d635eb9641b' ); $parser = new Parser; print_r($parser->parse($diff)); ``` -------------------------------- ### PHP Diff Component API Fixes (v4.0.4) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet addresses an issue in version 4.0.4 where SebastianBergmannDiffException did not correctly extend \Throwable. This fix ensures proper exception handling in line with modern PHP standards. ```PHP /* * SebastianBergmann\Diff\Exception extension fix in v4.0.4 */ Exception extends \Throwable ``` -------------------------------- ### PHP Diff Component API Changes (v5.0.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details a significant change in the constructor of SebastianBergmannDiffDiffer in version 5.0.0. The DiffOutputBuilderInterface instance is now a mandatory parameter, impacting how Diff objects are instantiated. ```PHP /* * SebastianBergmann\Diff\Differ constructor change in v5.0.0 */ Differ::__construct(DiffOutputBuilderInterface $outputBuilder) ``` -------------------------------- ### PHP Diff Component API Changes (v3.0.1) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details the removal of 'minimum-stability: dev' from composer.json in version 3.0.1, which affects package stability settings. ```PHP /* * composer.json 'minimum-stability' change in v3.0.1 */ composer.json: Removed: "minimum-stability": "dev" ``` -------------------------------- ### PHP Diff Component API Additions (v5.1.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details new methods added to the SebastianBergmannDiffChunk and SebastianBergmannDiffDiff classes in version 5.1.0, enhancing iteration and data access. It also introduces new methods for Line objects to check their status (added, removed, unchanged). ```PHP /* * SebastianBergmann\Diff\Chunk methods added in v5.1.0 */ Chunk::start() Chunk::startRange() Chunk::end() Chunk::endRange() Chunk::lines() /* * SebastianBergmann\Diff\Diff methods added in v5.1.0 */ Diff::from() Diff::to() Diff::chunks() /* * SebastianBergmann\Diff\Line methods added in v5.1.0 */ Line::content() Diff::type() Line::isAdded() Line::isRemoved() Line::isUnchanged() /* * IteratorAggregate implementations added in v5.1.0 */ Diff implements IteratorAggregate // yields Chunk objects Chunk implements IteratorAggregate // yields Line objects ``` -------------------------------- ### PHP Diff Component API Deprecations (v5.1.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet highlights methods that were deprecated in version 5.1.0 of the SebastianBergmannDiff component. These methods are marked for future removal and users are advised to use the newer alternatives introduced in the same version. ```PHP /* * SebastianBergmann\Diff\Chunk methods deprecated in v5.1.0 */ Chunk::getStart() Chunk::getStartRange() Chunk::getEnd() Chunk::getEndRange() Chunk::getLines() /* * SebastianBergmann\Diff\Diff methods deprecated in v5.1.0 */ Diff::getFrom() Diff::getTo() Diff::getChunks() /* * SebastianBergmann\Diff\Line and SebastianBergmann\Diff\Diff methods deprecated in v5.1.0 */ Line::getContent() Diff::getType() ``` -------------------------------- ### PHP Diff Component API Additions (v4.0.2) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet notes that support for PHP 8 was added to the diff component in version 4.0.2, ensuring compatibility with the latest PHP versions. ```PHP /* * PHP 8 support added in v4.0.2 */ PHP 8 compatibility ``` -------------------------------- ### PHP Diff Component API Fixes (v2.0.1) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details the restoration of backward compatibility for specific PHPUnit versions (6.1.4 to 6.2.3) in version 2.0.1 of the diff component. ```PHP /* * PHPUnit backward compatibility restoration in v2.0.1 */ Diff component compatibility with PHPUnit 6.1.4, 6.2.0, 6.2.1, 6.2.2, 6.2.3 ``` -------------------------------- ### PHP Diff Component API Changes (v5.0.2) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details performance improvements made to the MemoryEfficientLongestCommonSubsequenceCalculator in version 5.0.2, addressing issue #118. ```PHP /* * Performance improvement for MemoryEfficientLongestCommonSubsequenceCalculator in v5.0.2 */ SebastianBergmann\Diff\LCS\MemoryEfficientLongestCommonSubsequenceCalculator ``` -------------------------------- ### Add Constant THREE to Foo.php Source: https://github.com/sebastianbergmann/diff/blob/main/tests/fixtures/patch.txt This snippet shows the addition of the constant 'THREE' to the Foo class in Foo.php. It highlights a minor change in the class definition. ```php diff --git a/Foo.php b/Foo.php index abcdefg..abcdefh 100644 --- a/Foo.php +++ b/Foo.php @@ -20,4 +20,5 @@ class Foo const ONE = 1; const TWO = 2; + const THREE = 3; const FOUR = 4; ``` -------------------------------- ### PHP Diff Component API Additions (v2.0.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet highlights the addition of line number display for diff chunks in version 2.0.0, improving the readability and usability of diff outputs. ```PHP /* * Line number display for diff chunks added in v2.0.0 */ DiffOutputBuilderInterface::showLineNumbers() ``` -------------------------------- ### PHP Diff Component API Changes (v5.0.3) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details performance improvements made to the TimeEfficientLongestCommonSubsequenceCalculator in version 5.0.3, addressing issue #119. ```PHP /* * Performance improvement for TimeEfficientLongestCommonSubsequenceCalculator in v5.0.3 */ SebastianBergmann\Diff\LCS\TimeEfficientLongestCommonSubsequenceCalculator ``` -------------------------------- ### PHP Diff Component API Fixes (v3.0.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet addresses an issue in version 3.0.0 where diffing arrays was not functioning correctly. It also notes a change in the default DiffOutputBuilderInterface implementation to include context lines. ```PHP /* * Array diffing fix in v3.0.0 */ Diff::diffToArray() /* * Default DiffOutputBuilderInterface change in v3.0.0 */ DiffOutputBuilderInterface::defaultImplementation() // Now generates context lines ``` -------------------------------- ### PHP Diff Component API Changes (v4.0.3) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details the change in PHP version constraint in composer.json from '^7.3 || ^8.0' to '>=7.3' in version 4.0.3, broadening compatibility. ```PHP /* * Composer PHP version constraint change in v4.0.3 */ composer.json: "require": { "php": ">=7.3" } ``` -------------------------------- ### PHP Diff Component API Removals (v6.0.0) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet lists methods removed from the SebastianBergmannDiffChunk and SebastianBergmannDiffDiff classes in version 6.0.0. These removals are part of API cleanup and do not affect the core functionality of the diff component. ```PHP /* * SebastianBergmann\Diff\Chunk methods removed in v6.0.0 */ Chunk::getStart() Chunk::getStartRange() Chunk::getEnd() Chunk::getEndRange() Chunk::getLines() /* * SebastianBergmann\Diff\Diff methods removed in v6.0.0 */ Diff::getFrom() Diff::getTo() Diff::getChunks() /* * SebastianBergmann\Diff\Line and SebastianBergmann\Diff\Diff methods removed in v6.0.0 */ Line::getContent() Diff::getType() ``` -------------------------------- ### PHP Diff Component API Fixes (v4.0.1) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet addresses a regression in the unified diff output for identical strings, as fixed in version 4.0.1. This ensures accurate representation of unchanged content in diffs. ```PHP /* * Unified diff output regression fix for identical strings in v4.0.1 */ DiffOutputBuilderInterface::unifiedDiff() ``` -------------------------------- ### PHP Diff Component API Fixes (v5.0.1) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details a fix in version 5.0.1 for the Parser::parseFileDiff() method. The issue involved incorrect handling of diffs that contained only added or only removed lines. ```PHP /* * Parser::parseFileDiff() fix for single-sided diffs in v5.0.1 */ Parser::parseFileDiff() ``` -------------------------------- ### PHP Diff Component API Fixes (v3.0.2) Source: https://github.com/sebastianbergmann/diff/blob/main/ChangeLog.md This snippet details a change in Chunk::setLines() in version 3.0.2. The method now enforces that the provided lines array exclusively contains Line objects, improving data integrity. ```PHP /* * Chunk::setLines() data integrity fix in v3.0.2 */ Chunk::setLines(array $lines) // Ensures all elements in $lines are Line objects ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.