Skip to content

Commit 86ba64b

Browse files
Revert "Refactor"
This reverts commit 85c3093.
1 parent 85c3093 commit 86ba64b

8 files changed

+42
-33
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\LongestCommonSubsequenceCalculator;
14-
use SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator;
15-
use SebastianBergmann\Diff\MemoryEfficientLongestCommonSubsequenceCalculator;
13+
use SebastianBergmann\Diff\LCS\LongestCommonSubsequence;
14+
use SebastianBergmann\Diff\LCS\TimeEfficientImplementation;
15+
use SebastianBergmann\Diff\LCS\MemoryEfficientImplementation;
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 LongestCommonSubsequenceCalculator $lcs
47+
* @param LongestCommonSubsequence $lcs
4848
*
4949
* @return string
5050
*/
51-
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
51+
public function diff($from, $to, LongestCommonSubsequence $lcs = null)
5252
{
5353
$from = $this->validateDiffInput($from);
5454
$to = $this->validateDiffInput($to);
@@ -185,11 +185,11 @@ private function getDiffBufferElement($diff, $i, $newChunk, $buffer)
185185
*
186186
* @param array|string $from
187187
* @param array|string $to
188-
* @param LongestCommonSubsequenceCalculator $lcs
188+
* @param LongestCommonSubsequence $lcs
189189
*
190190
* @return array
191191
*/
192-
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
192+
public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
193193
{
194194
if (\is_string($from)) {
195195
$fromMatches = $this->getNewLineMatches($from);
@@ -296,7 +296,7 @@ private function splitStringByLines($input)
296296
* @param array $from
297297
* @param array $to
298298
*
299-
* @return LongestCommonSubsequenceCalculator
299+
* @return LongestCommonSubsequence
300300
*/
301301
private function selectLcsImplementation(array $from, array $to)
302302
{
@@ -307,10 +307,10 @@ private function selectLcsImplementation(array $from, array $to)
307307
$memoryLimit = 100 * 1024 * 1024;
308308

309309
if ($this->calculateEstimatedFootprint($from, $to) > $memoryLimit) {
310-
return new MemoryEfficientLongestCommonSubsequenceCalculator;
310+
return new MemoryEfficientImplementation;
311311
}
312312

313-
return new TimeEfficientLongestCommonSubsequenceCalculator;
313+
return new TimeEfficientImplementation;
314314
}
315315

316316
/**

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

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

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

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

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

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

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

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

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

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

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

13-
class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
13+
/**
14+
* Time-efficient implementation of longest common subsequence calculation.
15+
*/
16+
class TimeEfficientImplementation implements LongestCommonSubsequence
1417
{
1518
/**
1619
* 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\MemoryEfficientLongestCommonSubsequenceCalculator;
14-
use SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator;
13+
use SebastianBergmann\Diff\LCS\MemoryEfficientImplementation;
14+
use SebastianBergmann\Diff\LCS\TimeEfficientImplementation;
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
1818
* @covers SebastianBergmann\Diff\Differ
1919
*
20-
* @uses SebastianBergmann\Diff\MemoryEfficientImplementation
21-
* @uses SebastianBergmann\Diff\TimeEfficientImplementation
20+
* @uses SebastianBergmann\Diff\LCS\MemoryEfficientImplementation
21+
* @uses SebastianBergmann\Diff\LCS\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 TimeEfficientLongestCommonSubsequenceCalculator));
51+
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new TimeEfficientImplementation));
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 TimeEfficientLongestCommonSubsequenceCalculator));
62+
$this->assertEquals($expected, $this->differ->diff($from, $to, new TimeEfficientImplementation));
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 MemoryEfficientLongestCommonSubsequenceCalculator));
73+
$this->assertEquals($expected, $this->differ->diffToArray($from, $to, new MemoryEfficientImplementation));
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 MemoryEfficientLongestCommonSubsequenceCalculator));
84+
$this->assertEquals($expected, $this->differ->diff($from, $to, new MemoryEfficientImplementation));
8585
}
8686

8787
public function testCustomHeaderCanBeUsed()

tests/LongestCommonSubsequenceTest.php renamed to tests/LCS/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;
11+
namespace SebastianBergmann\Diff\LCS;
1212

1313
use PHPUnit\Framework\TestCase;
1414

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

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

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

tests/MemoryEfficientImplementationTest.php renamed to tests/LCS/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;
11+
namespace SebastianBergmann\Diff\LCS;
1212

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

tests/TimeEfficientImplementationTest.php renamed to tests/LCS/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;
11+
namespace SebastianBergmann\Diff\LCS;
1212

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

0 commit comments

Comments
 (0)