Skip to content

Add Diff v3 backport #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keradus why was change needed for v3.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i copy-pasted v1 from original repo as well, that was the change from there

'#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]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keradus same here, not sure why this change is needed for v3.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i copy-pasted v2 from original repo as well, that was the change from there

\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