Skip to content

Commit 1c9d9d7

Browse files
authored
Merge pull request #43 from JBlond/followup-42
follow up #42
2 parents 3a52371 + 8586225 commit 1c9d9d7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/jblond/Diff/Renderer/SequenceMatcherHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SequenceMatcherHelper
2525
* @param mixed $default The value to return as the default value if the key doesn't exist.
2626
* @return mixed The value from the array if the key exists or otherwise the default.
2727
*/
28-
protected function arrayGetDefault(array $array, $key, $default)
28+
public static function arrayGetDefault(array $array, $key, $default)
2929
{
3030
if (isset($array[$key])) {
3131
return $array[$key];
@@ -40,7 +40,7 @@ protected function arrayGetDefault(array $array, $key, $default)
4040
* @param array $bArray Second array to compare.
4141
* @return int -1, 0 or 1, as expected by the usort function.
4242
*/
43-
protected function tupleSort(array $aArray, array $bArray): int
43+
public static function tupleSort(array $aArray, array $bArray): int
4444
{
4545
$max = max(count($aArray), count($bArray));
4646
for ($counter = 0; $counter < $max; ++$counter) {

lib/jblond/Diff/SequenceMatcher.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use jblond\Diff\Renderer\SequenceMatcherHelper;
99

10+
1011
/**
1112
* Sequence matcher for Diff
1213
*
@@ -21,7 +22,7 @@
2122
* @version 2.0.0
2223
* @link https://github.com/JBlond/php-diff
2324
*/
24-
class SequenceMatcher extends SequenceMatcherHelper
25+
class SequenceMatcher
2526
{
2627
/**
2728
* @var string|array Either a string or an array containing a callback function to determine
@@ -258,15 +259,15 @@ public function findLongestMatch(int $aLower, int $aUpper, int $bLower, int $bUp
258259

259260
for ($i = $aLower; $i < $aUpper; ++$i) {
260261
$newJ2Len = [];
261-
$jDict = $this->arrayGetDefault($this->b2j, $old[$i], $nothing);
262+
$jDict = SequenceMatcherHelper::arrayGetDefault($this->b2j, $old[$i], $nothing);
262263
foreach ($jDict as $j) {
263264
if ($j < $bLower) {
264265
continue;
265266
} elseif ($j >= $bUpper) {
266267
break;
267268
}
268269

269-
$k = $this->arrayGetDefault($j2Len, $j - 1, 0) + 1;
270+
$k = SequenceMatcherHelper::arrayGetDefault($j2Len, $j - 1, 0) + 1;
270271
$newJ2Len[$j] = $k;
271272
if ($k > $bestSize) {
272273
$bestI = $i - $k + 1;
@@ -413,7 +414,7 @@ public function getMatchingBlocks(): array
413414
usort(
414415
$matchingBlocks,
415416
function ($aArray, $bArray) {
416-
return $this->tupleSort($aArray, $bArray);
417+
return SequenceMatcherHelper::tupleSort($aArray, $bArray);
417418
}
418419
);
419420

0 commit comments

Comments
 (0)