Skip to content

Commit 45ef3e4

Browse files
committed
Backport for PHP 5.6.
1 parent 347c1d8 commit 45ef3e4

31 files changed

+173
-242
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
[*]
3+
end_of_line = lf
4+
insert_final_newline = true
5+
indent_style = space
6+
indent_size = 4
7+
trim_trailing_whitespace = true

.gitattributes

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/ export-ignore
2+
.editorconfig export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
.php_cs export-ignore
6+
.travis.yml export-ignore
7+
build.xml export-ignore
8+
phpunit.xml.dist export-ignore
9+
* text=auto eol=lf
10+
*.php text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
11+
*.json text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
12+
*.yml text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
13+
*.md text whitespace=blank-at-eol,blank-at-eof

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/.idea
21
/composer.lock
3-
/vendor
4-
/.php_cs.cache
5-
/from.txt.orig
2+
/phpunit.xml
3+
/vendor/

.travis.yml

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
language: php
22

3-
php:
4-
- 7.0
5-
- 7.0snapshot
6-
- 7.1
7-
- 7.1snapshot
8-
- master
3+
git:
4+
depth: 1
95

106
sudo: false
117

12-
before_install:
13-
- composer self-update
14-
- composer clear-cache
8+
matrix:
9+
fast_finish: true
10+
include:
11+
- php: 5.6
12+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
13+
- php: 7.0
14+
env: COMPOSER_FLAGS="--prefer-stable"
15+
- php: 7.1
16+
env: COMPOSER_FLAGS="--prefer-stable"
17+
- php: nightly
18+
env: COMPOSER_FLAGS="--dev --ignore-platform-reqs"
19+
allow_failures:
20+
- php: nightly
1521

1622
install:
17-
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable
23+
- travis_retry composer update $COMPOSER_FLAGS --no-interaction -v
24+
- composer info -D | sort
1825

1926
script:
20-
- ./vendor/bin/phpunit --coverage-clover=coverage.xml
21-
22-
after_success:
23-
- bash <(curl -s https://codecov.io/bash)
24-
25-
notifications:
26-
email: false
27-
27+
- phpenv config-rm xdebug.ini || return 0
28+
- ./vendor/bin/phpunit --verbose

README.md

+4-123
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,7 @@
1-
# sebastian/diff
1+
# PHP-CS-Fixer/diff
22

3-
Diff implementation for PHP, factored out of PHPUnit into a stand-alone component.
3+
Fork of sebastian/diff
44

5-
## Installation
5+
This is version is for PHP CS Fixer only!
66

7-
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
8-
9-
composer require sebastian/diff
10-
11-
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:
12-
13-
composer require --dev sebastian/diff
14-
15-
### Usage
16-
17-
The `Differ` class can be used to generate a textual representation of the difference between two strings:
18-
19-
```php
20-
use SebastianBergmann\Diff\Differ;
21-
22-
$differ = new Differ;
23-
print $differ->diff('foo', 'bar');
24-
```
25-
26-
The code above yields the output below:
27-
28-
--- Original
29-
+++ New
30-
@@ @@
31-
-foo
32-
+bar
33-
34-
The `Parser` class can be used to parse a unified diff into an object graph:
35-
36-
```php
37-
use SebastianBergmann\Diff\Parser;
38-
use SebastianBergmann\Git;
39-
40-
$git = new Git('/usr/local/src/money');
41-
42-
$diff = $git->getDiff(
43-
'948a1a07768d8edd10dcefa8315c1cbeffb31833',
44-
'c07a373d2399f3e686234c4f7f088d635eb9641b'
45-
);
46-
47-
$parser = new Parser;
48-
49-
print_r($parser->parse($diff));
50-
```
51-
52-
The code above yields the output below:
53-
54-
Array
55-
(
56-
[0] => SebastianBergmann\Diff\Diff Object
57-
(
58-
[from:SebastianBergmann\Diff\Diff:private] => a/tests/MoneyTest.php
59-
[to:SebastianBergmann\Diff\Diff:private] => b/tests/MoneyTest.php
60-
[chunks:SebastianBergmann\Diff\Diff:private] => Array
61-
(
62-
[0] => SebastianBergmann\Diff\Chunk Object
63-
(
64-
[start:SebastianBergmann\Diff\Chunk:private] => 87
65-
[startRange:SebastianBergmann\Diff\Chunk:private] => 7
66-
[end:SebastianBergmann\Diff\Chunk:private] => 87
67-
[endRange:SebastianBergmann\Diff\Chunk:private] => 7
68-
[lines:SebastianBergmann\Diff\Chunk:private] => Array
69-
(
70-
[0] => SebastianBergmann\Diff\Line Object
71-
(
72-
[type:SebastianBergmann\Diff\Line:private] => 3
73-
[content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::add
74-
)
75-
76-
[1] => SebastianBergmann\Diff\Line Object
77-
(
78-
[type:SebastianBergmann\Diff\Line:private] => 3
79-
[content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::newMoney
80-
)
81-
82-
[2] => SebastianBergmann\Diff\Line Object
83-
(
84-
[type:SebastianBergmann\Diff\Line:private] => 3
85-
[content:SebastianBergmann\Diff\Line:private] => */
86-
)
87-
88-
[3] => SebastianBergmann\Diff\Line Object
89-
(
90-
[type:SebastianBergmann\Diff\Line:private] => 2
91-
[content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyWithSameCurrencyObjectCanBeAdded()
92-
)
93-
94-
[4] => SebastianBergmann\Diff\Line Object
95-
(
96-
[type:SebastianBergmann\Diff\Line:private] => 1
97-
[content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyObjectWithSameCurrencyCanBeAdded()
98-
)
99-
100-
[5] => SebastianBergmann\Diff\Line Object
101-
(
102-
[type:SebastianBergmann\Diff\Line:private] => 3
103-
[content:SebastianBergmann\Diff\Line:private] => {
104-
)
105-
106-
[6] => SebastianBergmann\Diff\Line Object
107-
(
108-
[type:SebastianBergmann\Diff\Line:private] => 3
109-
[content:SebastianBergmann\Diff\Line:private] => $a = new Money(1, new Currency('EUR'));
110-
)
111-
112-
[7] => SebastianBergmann\Diff\Line Object
113-
(
114-
[type:SebastianBergmann\Diff\Line:private] => 3
115-
[content:SebastianBergmann\Diff\Line:private] => $b = new Money(2, new Currency('EUR'));
116-
)
117-
118-
)
119-
120-
)
121-
122-
)
123-
124-
)
125-
126-
)
7+
Do not use it!

composer.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "sebastian/diff",
3-
"description": "Diff implementation",
2+
"name": "PHP-CS-Fixer/diff",
3+
"description": "sebastian/diff v2 backport support for PHP5.6",
44
"keywords": ["diff"],
5-
"homepage": "https://github.com/sebastianbergmann/diff",
5+
"homepage": "https://github.com/PHP-CS-Fixer",
66
"license": "BSD-3-Clause",
77
"authors": [
88
{
@@ -15,19 +15,17 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.0"
18+
"php": "^5.6 || >=7.0 <7.2"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^6.2"
21+
"phpunit/phpunit": "^4.8.35 || ^5.4.3"
2222
},
2323
"autoload": {
2424
"classmap": [
2525
"src/"
2626
]
2727
},
28-
"extra": {
29-
"branch-alias": {
30-
"dev-master": "2.0-dev"
31-
}
28+
"autoload-dev": {
29+
"psr-4": { "SebastianBergmann\\Diff\\Tests\\": "tests/" }
3230
}
3331
}
File renamed without changes.

src/Chunk.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/*
33
* This file is part of sebastian/diff.
44
*
@@ -37,7 +37,7 @@ final class Chunk
3737
*/
3838
private $lines;
3939

40-
public function __construct(int $start = 0, int $startRange = 1, int $end = 0, int $endRange = 1, array $lines = [])
40+
public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
4141
{
4242
$this->start = $start;
4343
$this->startRange = $startRange;
@@ -46,27 +46,27 @@ public function __construct(int $start = 0, int $startRange = 1, int $end = 0, i
4646
$this->lines = $lines;
4747
}
4848

49-
public function getStart(): int
49+
public function getStart()
5050
{
5151
return $this->start;
5252
}
5353

54-
public function getStartRange(): int
54+
public function getStartRange()
5555
{
5656
return $this->startRange;
5757
}
5858

59-
public function getEnd(): int
59+
public function getEnd()
6060
{
6161
return $this->end;
6262
}
6363

64-
public function getEndRange(): int
64+
public function getEndRange()
6565
{
6666
return $this->endRange;
6767
}
6868

69-
public function getLines(): array
69+
public function getLines()
7070
{
7171
return $this->lines;
7272
}

src/Diff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/*
33
* This file is part of sebastian/diff.
44
*
@@ -32,27 +32,27 @@ final class Diff
3232
* @param string $to
3333
* @param Chunk[] $chunks
3434
*/
35-
public function __construct(string $from, string $to, array $chunks = [])
35+
public function __construct($from, $to, array $chunks = [])
3636
{
3737
$this->from = $from;
3838
$this->to = $to;
3939
$this->chunks = $chunks;
4040
}
4141

42-
public function getFrom(): string
42+
public function getFrom()
4343
{
4444
return $this->from;
4545
}
4646

47-
public function getTo(): string
47+
public function getTo()
4848
{
4949
return $this->to;
5050
}
5151

5252
/**
5353
* @return Chunk[]
5454
*/
55-
public function getChunks(): array
55+
public function getChunks()
5656
{
5757
return $this->chunks;
5858
}

0 commit comments

Comments
 (0)