Skip to content

Commit 85c3093

Browse files
Refactor
1 parent 66ae227 commit 85c3093

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);
@@ -185,11 +185,11 @@ private function getDiffBufferElement($diff, $i, $newChunk, $buffer)
185185
*
186186
* @param array|string $from
187187
* @param array|string $to
188-
* @param LongestCommonSubsequence $lcs
188+
* @param LongestCommonSubsequenceCalculator $lcs
189189
*
190190
* @return array
191191
*/
192-
public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
192+
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $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 LongestCommonSubsequence
299+
* @return LongestCommonSubsequenceCalculator
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 MemoryEfficientImplementation;
310+
return new MemoryEfficientLongestCommonSubsequenceCalculator;
311311
}
312312

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

316316
/**

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)