Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sebastianbergmann/diff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: PHP-CS-Fixer/diff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.

Commits on Aug 22, 2017

  1. Backport for PHP 5.6.

    SpacePossum committed Aug 22, 2017
    Copy the full SHA
    45ef3e4 View commit details
  2. Copy the full SHA
    8da5762 View commit details

Commits on Aug 23, 2017

  1. Switch NS

    SpacePossum committed Aug 23, 2017
    Copy the full SHA
    864c4ab View commit details

Commits on Sep 18, 2017

  1. Copy the full SHA
    df047a5 View commit details
  2. Update ChangeLog.md

    SpacePossum authored Sep 18, 2017
    Copy the full SHA
    00695bd View commit details

Commits on Sep 23, 2017

  1. Allow to use on PHP 7.2

    keradus authored and SpacePossum committed Sep 23, 2017
    Copy the full SHA
    d068eda View commit details

Commits on Oct 5, 2017

  1. Copy the full SHA
    5a46d71 View commit details

Commits on Oct 6, 2017

  1. Update DifferTest.php

    SpacePossum authored Oct 6, 2017
    Copy the full SHA
    b135a0e View commit details

Commits on Oct 19, 2017

  1. Copy the full SHA
    f0ef613 View commit details
  2. Update composer.json

    SpacePossum authored Oct 19, 2017
    Copy the full SHA
    c247cb0 View commit details

Commits on Oct 21, 2017

  1. Update README.md

    SpacePossum authored Oct 21, 2017
    Copy the full SHA
    6ef825b View commit details
  2. Update LICENSE_DIFF

    SpacePossum authored Oct 21, 2017
    Copy the full SHA
    b95b8c0 View commit details

Commits on Feb 15, 2018

  1. Add Diff v3 backport (#7)

    * add v3 "as-is"
    keradus authored and SpacePossum committed Feb 15, 2018
    Copy the full SHA
    78bb099 View commit details

Commits on Mar 27, 2018

  1. Backport only new Diff v3 (#9)

    keradus authored and SpacePossum committed Mar 27, 2018
    Copy the full SHA
    1325493 View commit details
  2. Update composer.json

    SpacePossum authored Mar 27, 2018
    Copy the full SHA
    8f57f0c View commit details
  3. Update LICENSE

    SpacePossum authored Mar 27, 2018
    Copy the full SHA
    d4c6b32 View commit details

Commits on Aug 20, 2018

  1. Delete ChangeLog.md (#10)

    Changelog is confusing only, it mention only one release, while there are few more.
    keradus authored and SpacePossum committed Aug 20, 2018
    Copy the full SHA
    bcefc95 View commit details

Commits on Aug 27, 2019

  1. Simplify license (#14)

    keradus authored Aug 27, 2019
    Copy the full SHA
    1050bd5 View commit details
  2. DX: cleanup .gitignore (#12)

    keradus committed Aug 27, 2019
    Copy the full SHA
    ad7130c View commit details

Commits on Sep 4, 2019

  1. Copy the full SHA
    0adf6e5 View commit details
  2. Copy the full SHA
    834b52c View commit details

Commits on Jan 15, 2020

  1. Test on PHP 7.4 (#17)

    SpacePossum authored Jan 15, 2020
    Copy the full SHA
    c7fe15b View commit details

Commits on Oct 14, 2020

  1. PHP8 (#20)

    SpacePossum authored Oct 14, 2020
    Copy the full SHA
    29dc0d5 View commit details

Commits on Dec 4, 2024

  1. Create SECURITY.md

    keradus authored Dec 4, 2024
    Copy the full SHA
    856de6d View commit details
Showing with 3,993 additions and 1,176 deletions.
  1. +7 −0 .editorconfig
  2. +13 −0 .gitattributes
  3. +5 −0 .github/SECURITY.md
  4. +2 −4 .gitignore
  5. +25 −18 .travis.yml
  6. +0 −22 ChangeLog.md
  7. +0 −2 LICENSE
  8. +7 −123 README.md
  9. +13 −8 composer.json
  10. 0 phpunit.xml → phpunit.xml.dist
  11. +21 −9 src/Chunk.php
  12. +6 −6 src/Diff.php
  13. +53 −45 src/Differ.php
  14. +40 −0 src/Exception/ConfigurationException.php
  15. +2 −2 src/Exception/Exception.php
  16. +2 −2 src/Exception/InvalidArgumentException.php
  17. +5 −5 src/Line.php
  18. +3 −3 src/LongestCommonSubsequenceCalculator.php
  19. +4 −4 src/MemoryEfficientLongestCommonSubsequenceCalculator.php
  20. +3 −3 src/Output/AbstractChunkOutputBuilder.php
  21. +10 −7 src/Output/DiffOnlyOutputBuilder.php
  22. +4 −3 src/Output/DiffOutputBuilderInterface.php
  23. +315 −0 src/Output/StrictUnifiedDiffOutputBuilder.php
  24. +173 −79 src/Output/UnifiedDiffOutputBuilder.php
  25. +3 −3 src/Parser.php
  26. +3 −3 src/TimeEfficientLongestCommonSubsequenceCalculator.php
  27. +14 −7 tests/ChunkTest.php
  28. +4 −4 tests/DiffTest.php
  29. +115 −695 tests/DifferTest.php
  30. +0 −83 tests/DifferTestTest.php
  31. +41 −0 tests/Exception/ConfigurationExceptionTest.php
  32. +33 −0 tests/Exception/InvalidArgumentExceptionTest.php
  33. +3 −3 tests/LineTest.php
  34. +10 −10 tests/LongestCommonSubsequenceTest.php
  35. +3 −3 tests/MemoryEfficientImplementationTest.php
  36. +154 −0 tests/Output/AbstractChunkOutputBuilderTest.php
  37. +76 −0 tests/Output/DiffOnlyOutputBuilderTest.php
  38. +300 −0 tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php
  39. +163 −0 tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php
  40. +189 −0 tests/Output/StrictUnifiedDiffOutputBuilderDataProvider.php
  41. +715 −0 tests/Output/StrictUnifiedDiffOutputBuilderTest.php
  42. +396 −0 tests/Output/UnifiedDiffOutputBuilderDataProvider.php
  43. +114 −0 tests/Output/UnifiedDiffOutputBuilderTest.php
  44. +13 −17 tests/ParserTest.php
  45. +3 −3 tests/TimeEfficientImplementationTest.php
  46. +30 −0 tests/Utils/FileUtils.php
  47. +277 −0 tests/Utils/UnifiedDiffAssertTrait.php
  48. +129 −0 tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php
  49. +434 −0 tests/Utils/UnifiedDiffAssertTraitTest.php
  50. +1 −0 tests/fixtures/.editorconfig
  51. +1 −0 tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_a.txt
  52. 0 tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/1_b.txt
  53. +35 −0 tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_a.txt
  54. +18 −0 tests/fixtures/UnifiedDiffAssertTraitIntegrationTest/2_b.txt
  55. +1 −0 tests/fixtures/out/.editorconfig
  56. +2 −0 tests/fixtures/out/.gitignore
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/ export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
build.xml export-ignore
phpunit.xml.dist export-ignore
* text=auto eol=lf
*.php text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
*.json text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
*.yml text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
*.md text whitespace=blank-at-eol,blank-at-eof
5 changes: 5 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/PHP-CS-Fixer/diff/security/advisories/new) tab.

Report security bugs in third-party libraries to the person or team maintaining that library.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/.idea
/composer.lock
/vendor
/.php_cs.cache
/from.txt.orig
/phpunit.xml
/vendor/
43 changes: 25 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
language: php

php:
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- master
git:
depth: 1

sudo: false

before_install:
- composer self-update
- composer clear-cache
matrix:
fast_finish: true
include:
- php: 5.6
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.0
env: COMPOSER_FLAGS="--prefer-stable"
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable"
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable"
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable"
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable"
- php: nightly
env: COMPOSER_FLAGS="--dev --ignore-platform-reqs"
allow_failures:
- php: nightly

install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable
- travis_retry composer update $COMPOSER_FLAGS --no-interaction -v
- composer info -D | sort

script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false

- phpenv config-rm xdebug.ini || return 0
- ./vendor/bin/phpunit --verbose
22 changes: 0 additions & 22 deletions ChangeLog.md

This file was deleted.

2 changes: 0 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sebastian/diff

Copyright (c) 2002-2017, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.

130 changes: 7 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,10 @@
# sebastian/diff
# PHP-CS-Fixer/diff

Diff implementation for PHP, factored out of PHPUnit into a stand-alone component.
This version is for PHP CS Fixer only! Do not use it!

## Installation
Code from `sebastian/diff` has been forked a republished by permission of Sebastian Bergmann.
Main change is to make the package compatible with older PHP engines.
Licenced with BSD-3-Clause @ see LICENSE, copyright (c) Sebastian Bergmann <sebastian@phpunit.de>
https://github.com/sebastianbergmann/diff

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

composer require sebastian/diff

If 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:

composer require --dev sebastian/diff

### Usage

The `Differ` class can be used to generate a textual representation of the difference between two strings:

```php
use SebastianBergmann\Diff\Differ;

$differ = new Differ;
print $differ->diff('foo', 'bar');
```

The code above yields the output below:

--- Original
+++ New
@@ @@
-foo
+bar

The `Parser` class can be used to parse a unified diff into an object graph:

```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));
```

The code above yields the output below:

Array
(
[0] => SebastianBergmann\Diff\Diff Object
(
[from:SebastianBergmann\Diff\Diff:private] => a/tests/MoneyTest.php
[to:SebastianBergmann\Diff\Diff:private] => b/tests/MoneyTest.php
[chunks:SebastianBergmann\Diff\Diff:private] => Array
(
[0] => SebastianBergmann\Diff\Chunk Object
(
[start:SebastianBergmann\Diff\Chunk:private] => 87
[startRange:SebastianBergmann\Diff\Chunk:private] => 7
[end:SebastianBergmann\Diff\Chunk:private] => 87
[endRange:SebastianBergmann\Diff\Chunk:private] => 7
[lines:SebastianBergmann\Diff\Chunk:private] => Array
(
[0] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::add
)

[1] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::newMoney
)

[2] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => */
)

[3] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 2
[content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyWithSameCurrencyObjectCanBeAdded()
)

[4] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 1
[content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyObjectWithSameCurrencyCanBeAdded()
)

[5] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => {
)

[6] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => $a = new Money(1, new Currency('EUR'));
)

[7] => SebastianBergmann\Diff\Line Object
(
[type:SebastianBergmann\Diff\Line:private] => 3
[content:SebastianBergmann\Diff\Line:private] => $b = new Money(2, new Currency('EUR'));
)

)

)

)

)

)
For questions visit us @ https://gitter.im/PHP-CS-Fixer/Lobby
21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "sebastian/diff",
"description": "Diff implementation",
"name": "php-cs-fixer/diff",
"description": "sebastian/diff v3 backport support for PHP 5.6+",
"keywords": ["diff"],
"homepage": "https://github.com/sebastianbergmann/diff",
"homepage": "https://github.com/PHP-CS-Fixer",
"license": "BSD-3-Clause",
"authors": [
{
@@ -15,19 +15,24 @@
}
],
"require": {
"php": "^7.0"
"php": "^5.6 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^6.2"
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0",
"symfony/process": "^3.3"
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"autoload": {
"classmap": [
"src/"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"autoload-dev": {
"psr-4": {
"PhpCsFixer\\Diff\\": "tests"
}
}
}
File renamed without changes.
30 changes: 21 additions & 9 deletions src/Chunk.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
* This file is part of sebastian/diff.
*
@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace SebastianBergmann\Diff;
namespace PhpCsFixer\Diff;

final class Chunk
{
@@ -33,11 +33,11 @@ final class Chunk
private $endRange;

/**
* @var array
* @var Line[]
*/
private $lines;

public function __construct(int $start = 0, int $startRange = 1, int $end = 0, int $endRange = 1, array $lines = [])
public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
{
$this->start = $start;
$this->startRange = $startRange;
@@ -46,33 +46,45 @@ public function __construct(int $start = 0, int $startRange = 1, int $end = 0, i
$this->lines = $lines;
}

public function getStart(): int
public function getStart()
{
return $this->start;
}

public function getStartRange(): int
public function getStartRange()
{
return $this->startRange;
}

public function getEnd(): int
public function getEnd()
{
return $this->end;
}

public function getEndRange(): int
public function getEndRange()
{
return $this->endRange;
}

public function getLines(): array
/**
* @return Line[]
*/
public function getLines()
{
return $this->lines;
}

/**
* @param Line[] $lines
*/
public function setLines(array $lines)
{
foreach ($lines as $line) {
if (!$line instanceof Line) {
throw new InvalidArgumentException;
}
}

$this->lines = $lines;
}
}
Loading