Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 22ef7d6

Browse files
Revert "Revert "Refactor""
This reverts commit 86ba64b.
1 parent 3c7d219 commit 22ef7d6

8 files changed

+33
-42
lines changed

src/Differ.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace SebastianBergmann\Diff;
1212

13-
use SebastianBergmann\Diff\LCS\LongestCommonSubsequence;
14-
use SebastianBergmann\Diff\LCS\TimeEfficientImplementation;
15-
use SebastianBergmann\Diff\LCS\MemoryEfficientImplementation;
13+
use SebastianBergmann\Diff\LongestCommonSubsequenceCalculator;
14+
use SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator;
15+
use SebastianBergmann\Diff\MemoryEfficientLongestCommonSubsequenceCalculator;
1616

1717
/**
1818
* Diff implementation.
@@ -44,11 +44,11 @@ public function __construct($header = "--- Original\n+++ New\n", $showNonDiffLin
4444
*
4545
* @param array|string $from
4646
* @param array|string $to
47-
* @param LongestCommonSubsequence $lcs
47+
* @param LongestCommonSubsequenceCalculator $lcs
4848
*
4949
* @return string
5050
*/
51-
public function diff($from, $to, LongestCommonSubsequence $lcs = null)
51+
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
5252
{
5353
$from = $this->validateDiffInput($from);
5454
$to = $this->validateDiffInput($to);
@@ -197,11 +197,11 @@ private function getDiffBufferElementNew(array $diff, $buffer, $diffIndex)
197197
*
198198
* @param array|string $from
199199
* @param array|string $to
200-
* @param LongestCommonSubsequence $lcs
200+
* @param LongestCommonSubsequenceCalculator $lcs
201201
*
202202
* @return array
203203
*/
204-
public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
204+
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
205205
{
206206
if (\is_string($from)) {
207207
$fromMatches = $this->getNewLineMatches($from);
@@ -304,7 +304,7 @@ private function splitStringByLines($input)
304304
* @param array $from
305305
* @param array $to
306306
*
307-
* @return LongestCommonSubsequence
307+
* @return LongestCommonSubsequenceCalculator
308308
*/
309309
private function selectLcsImplementation(array $from, array $to)
310310
{
@@ -315,10 +315,10 @@ private function selectLcsImplementation(array $from, array $to)
315315
$memoryLimit = 100 * 1024 * 1024;
316316

317317
if ($this->calculateEstimatedFootprint($from, $to) > $memoryLimit) {
318-
return new MemoryEfficientImplementation;
318+
return new MemoryEfficientLongestCommonSubsequenceCalculator;
319319
}
320320

321-
return new TimeEfficientImplementation;
321+
return new TimeEfficientLongestCommonSubsequenceCalculator;
322322
}
323323

324324
/**

src/LCS/LongestCommonSubsequence.php renamed to src/LongestCommonSubsequenceCalculator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

13-
/**
14-
* Interface for implementations of longest common subsequence calculation.
15-
*/
16-
interface LongestCommonSubsequence
13+
interface LongestCommonSubsequenceCalculator
1714
{
1815
/**
1916
* Calculates the longest common subsequence of two arrays.

src/LCS/MemoryEfficientLongestCommonSubsequenceImplementation.php renamed to src/MemoryEfficientLongestCommonSubsequenceCalculator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

13-
/**
14-
* Memory-efficient implementation of longest common subsequence calculation.
15-
*/
16-
class MemoryEfficientImplementation implements LongestCommonSubsequence
13+
class MemoryEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
1714
{
1815
/**
1916
* Calculates the longest common subsequence of two arrays.

src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php renamed to src/TimeEfficientLongestCommonSubsequenceCalculator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

13-
/**
14-
* Time-efficient implementation of longest common subsequence calculation.
15-
*/
16-
class TimeEfficientImplementation implements LongestCommonSubsequence
13+
class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
1714
{
1815
/**
1916
* Calculates the longest common subsequence of two arrays.

tests/DifferTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
namespace SebastianBergmann\Diff;
1212

13-
use SebastianBergmann\Diff\LCS\MemoryEfficientImplementation;
14-
use SebastianBergmann\Diff\LCS\TimeEfficientImplementation;
13+
use SebastianBergmann\Diff\MemoryEfficientLongestCommonSubsequenceCalculator;
14+
use SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator;
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
1818
* @covers SebastianBergmann\Diff\Differ
1919
*
20-
* @uses SebastianBergmann\Diff\LCS\MemoryEfficientImplementation
21-
* @uses SebastianBergmann\Diff\LCS\TimeEfficientImplementation
20+
* @uses SebastianBergmann\Diff\MemoryEfficientImplementation
21+
* @uses SebastianBergmann\Diff\TimeEfficientImplementation
2222
* @uses SebastianBergmann\Diff\Chunk
2323
* @uses SebastianBergmann\Diff\Diff
2424
* @uses SebastianBergmann\Diff\Line
@@ -48,7 +48,7 @@ protected function setUp()
4848
*/
4949
public function testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation(array $expected, $from, $to)
5050
{
51-
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new TimeEfficientImplementation));
51+
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new TimeEfficientLongestCommonSubsequenceCalculator));
5252
}
5353

5454
/**
@@ -59,7 +59,7 @@ public function testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsI
5959
*/
6060
public function testTextRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation($expected, $from, $to)
6161
{
62-
$this->assertEquals($expected, $this->differ->diff($from, $to, new TimeEfficientImplementation));
62+
$this->assertEquals($expected, $this->differ->diff($from, $to, new TimeEfficientLongestCommonSubsequenceCalculator));
6363
}
6464

6565
/**
@@ -70,7 +70,7 @@ public function testTextRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsIm
7070
*/
7171
public function testArrayRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLcsImplementation(array $expected, $from, $to)
7272
{
73-
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new MemoryEfficientImplementation));
73+
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new MemoryEfficientLongestCommonSubsequenceCalculator));
7474
}
7575

7676
/**
@@ -81,7 +81,7 @@ public function testArrayRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLc
8181
*/
8282
public function testTextRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLcsImplementation($expected, $from, $to)
8383
{
84-
$this->assertEquals($expected, $this->differ->diff($from, $to, new MemoryEfficientImplementation));
84+
$this->assertEquals($expected, $this->differ->diff($from, $to, new MemoryEfficientLongestCommonSubsequenceCalculator));
8585
}
8686

8787
public function testCustomHeaderCanBeUsed()

tests/LCS/LongestCommonSubsequenceTest.php renamed to tests/LongestCommonSubsequenceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

1313
use PHPUnit\Framework\TestCase;
1414

1515
abstract class LongestCommonSubsequenceTest extends TestCase
1616
{
1717
/**
18-
* @var LongestCommonSubsequence
18+
* @var LongestCommonSubsequenceCalculator
1919
*/
2020
private $implementation;
2121

@@ -38,7 +38,7 @@ protected function setUp()
3838
}
3939

4040
/**
41-
* @return LongestCommonSubsequence
41+
* @return LongestCommonSubsequenceCalculator
4242
*/
4343
abstract protected function createImplementation();
4444

tests/LCS/MemoryEfficientImplementationTest.php renamed to tests/MemoryEfficientImplementationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

1313
/**
14-
* @covers SebastianBergmann\Diff\LCS\MemoryEfficientImplementation
14+
* @covers SebastianBergmann\Diff\MemoryEfficientImplementation
1515
*/
1616
class MemoryEfficientImplementationTest extends LongestCommonSubsequenceTest
1717
{
1818
protected function createImplementation()
1919
{
20-
return new MemoryEfficientImplementation;
20+
return new MemoryEfficientLongestCommonSubsequenceCalculator;
2121
}
2222
}

tests/LCS/TimeEfficientImplementationTest.php renamed to tests/TimeEfficientImplementationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace SebastianBergmann\Diff\LCS;
11+
namespace SebastianBergmann\Diff;
1212

1313
/**
14-
* @covers SebastianBergmann\Diff\LCS\TimeEfficientImplementation
14+
* @covers SebastianBergmann\Diff\TimeEfficientImplementation
1515
*/
1616
class TimeEfficientImplementationTest extends LongestCommonSubsequenceTest
1717
{
1818
protected function createImplementation()
1919
{
20-
return new TimeEfficientImplementation;
20+
return new TimeEfficientLongestCommonSubsequenceCalculator;
2121
}
2222
}

0 commit comments

Comments
 (0)