Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add Diff v3 backport (#7)
Browse files Browse the repository at this point in the history
* add v3 "as-is"
  • Loading branch information
keradus authored and SpacePossum committed Feb 15, 2018
1 parent b95b8c0 commit 78bb099
Show file tree
Hide file tree
Showing 52 changed files with 5,698 additions and 10 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"php": "^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.4.3",
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"symfony/process": "^3.3"
},
"autoload": {
Expand All @@ -33,6 +33,7 @@
"psr-4": {
"PhpCsFixer\\Diff\\v1_4\\Tests\\": "tests/v1_4",
"PhpCsFixer\\Diff\\v2_0\\Tests\\": "tests/v2_0",
"PhpCsFixer\\Diff\\v3_0\\": "tests/v3_0",
"PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\Tests\\": "tests/GeckoPackages/DiffOutputBuilder/Tests",
"PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\Utils\\": "tests/GeckoPackages/DiffOutputBuilder/Utils"
}
Expand Down
2 changes: 1 addition & 1 deletion src/v1_4/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)

if ($this->detectUnmatchedLineEndings($fromMatches, $toMatches)) {
$diff[] = array(
'#Warning: Strings contain different line endings!',
'#Warnings contain different line endings!',
0
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2_0/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
}

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

return $diff;
Expand Down
78 changes: 78 additions & 0 deletions src/v3_0/Chunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/*
* This file is part of sebastian/diff.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PhpCsFixer\Diff\v3_0;

final class Chunk
{
/**
* @var int
*/
private $start;

/**
* @var int
*/
private $startRange;

/**
* @var int
*/
private $end;

/**
* @var int
*/
private $endRange;

/**
* @var array
*/
private $lines;

public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
{
$this->start = $start;
$this->startRange = $startRange;
$this->end = $end;
$this->endRange = $endRange;
$this->lines = $lines;
}

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

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

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

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

public function getLines()
{
return $this->lines;
}

public function setLines(array $lines)
{
$this->lines = $lines;
}
}
67 changes: 67 additions & 0 deletions src/v3_0/Diff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
* This file is part of sebastian/diff.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PhpCsFixer\Diff\v3_0;

final class Diff
{
/**
* @var string
*/
private $from;

/**
* @var string
*/
private $to;

/**
* @var Chunk[]
*/
private $chunks;

/**
* @param string $from
* @param string $to
* @param Chunk[] $chunks
*/
public function __construct($from, $to, array $chunks = [])
{
$this->from = $from;
$this->to = $to;
$this->chunks = $chunks;
}

public function getFrom()
{
return $this->from;
}

public function getTo()
{
return $this->to;
}

/**
* @return Chunk[]
*/
public function getChunks()
{
return $this->chunks;
}

/**
* @param Chunk[] $chunks
*/
public function setChunks(array $chunks)
{
$this->chunks = $chunks;
}
}
Loading

0 comments on commit 78bb099

Please sign in to comment.