Skip to content

Commit 78bb099

Browse files
keradusSpacePossum
authored andcommitted
Add Diff v3 backport (#7)
* add v3 "as-is"
1 parent b95b8c0 commit 78bb099

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5698
-10
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"php": "^5.6 || ^7.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^4.8.35 || ^5.4.3",
24+
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
2525
"symfony/process": "^3.3"
2626
},
2727
"autoload": {
@@ -33,6 +33,7 @@
3333
"psr-4": {
3434
"PhpCsFixer\\Diff\\v1_4\\Tests\\": "tests/v1_4",
3535
"PhpCsFixer\\Diff\\v2_0\\Tests\\": "tests/v2_0",
36+
"PhpCsFixer\\Diff\\v3_0\\": "tests/v3_0",
3637
"PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\Tests\\": "tests/GeckoPackages/DiffOutputBuilder/Tests",
3738
"PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\Utils\\": "tests/GeckoPackages/DiffOutputBuilder/Utils"
3839
}

src/v1_4/Differ.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
232232

233233
if ($this->detectUnmatchedLineEndings($fromMatches, $toMatches)) {
234234
$diff[] = array(
235-
'#Warning: Strings contain different line endings!',
235+
'#Warnings contain different line endings!',
236236
0
237237
);
238238
}

src/v2_0/Differ.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
158158
}
159159

160160
if ($this->detectUnmatchedLineEndings($diff)) {
161-
\array_unshift($diff, ["#Warning: Strings contain different line endings!\n", 3]);
161+
\array_unshift($diff, ["#Warnings contain different line endings!\n", 3]);
162162
}
163163

164164
return $diff;

src/v3_0/Chunk.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/*
3+
* This file is part of sebastian/diff.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace PhpCsFixer\Diff\v3_0;
12+
13+
final class Chunk
14+
{
15+
/**
16+
* @var int
17+
*/
18+
private $start;
19+
20+
/**
21+
* @var int
22+
*/
23+
private $startRange;
24+
25+
/**
26+
* @var int
27+
*/
28+
private $end;
29+
30+
/**
31+
* @var int
32+
*/
33+
private $endRange;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $lines;
39+
40+
public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
41+
{
42+
$this->start = $start;
43+
$this->startRange = $startRange;
44+
$this->end = $end;
45+
$this->endRange = $endRange;
46+
$this->lines = $lines;
47+
}
48+
49+
public function getStart()
50+
{
51+
return $this->start;
52+
}
53+
54+
public function getStartRange()
55+
{
56+
return $this->startRange;
57+
}
58+
59+
public function getEnd()
60+
{
61+
return $this->end;
62+
}
63+
64+
public function getEndRange()
65+
{
66+
return $this->endRange;
67+
}
68+
69+
public function getLines()
70+
{
71+
return $this->lines;
72+
}
73+
74+
public function setLines(array $lines)
75+
{
76+
$this->lines = $lines;
77+
}
78+
}

src/v3_0/Diff.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/*
3+
* This file is part of sebastian/diff.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace PhpCsFixer\Diff\v3_0;
12+
13+
final class Diff
14+
{
15+
/**
16+
* @var string
17+
*/
18+
private $from;
19+
20+
/**
21+
* @var string
22+
*/
23+
private $to;
24+
25+
/**
26+
* @var Chunk[]
27+
*/
28+
private $chunks;
29+
30+
/**
31+
* @param string $from
32+
* @param string $to
33+
* @param Chunk[] $chunks
34+
*/
35+
public function __construct($from, $to, array $chunks = [])
36+
{
37+
$this->from = $from;
38+
$this->to = $to;
39+
$this->chunks = $chunks;
40+
}
41+
42+
public function getFrom()
43+
{
44+
return $this->from;
45+
}
46+
47+
public function getTo()
48+
{
49+
return $this->to;
50+
}
51+
52+
/**
53+
* @return Chunk[]
54+
*/
55+
public function getChunks()
56+
{
57+
return $this->chunks;
58+
}
59+
60+
/**
61+
* @param Chunk[] $chunks
62+
*/
63+
public function setChunks(array $chunks)
64+
{
65+
$this->chunks = $chunks;
66+
}
67+
}

0 commit comments

Comments
 (0)