Skip to content

follow up https://github.com/JBlond/php-diff/pull/42 #43

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 1 commit into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/jblond/Diff/Renderer/SequenceMatcherHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SequenceMatcherHelper
* @param mixed $default The value to return as the default value if the key doesn't exist.
* @return mixed The value from the array if the key exists or otherwise the default.
*/
protected function arrayGetDefault(array $array, $key, $default)
public static function arrayGetDefault(array $array, $key, $default)
{
if (isset($array[$key])) {
return $array[$key];
Expand All @@ -40,7 +40,7 @@ protected function arrayGetDefault(array $array, $key, $default)
* @param array $bArray Second array to compare.
* @return int -1, 0 or 1, as expected by the usort function.
*/
protected function tupleSort(array $aArray, array $bArray): int
public static function tupleSort(array $aArray, array $bArray): int
{
$max = max(count($aArray), count($bArray));
for ($counter = 0; $counter < $max; ++$counter) {
Expand Down
9 changes: 5 additions & 4 deletions lib/jblond/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use jblond\Diff\Renderer\SequenceMatcherHelper;


/**
* Sequence matcher for Diff
*
Expand All @@ -21,7 +22,7 @@
* @version 2.0.0
* @link https://github.com/JBlond/php-diff
*/
class SequenceMatcher extends SequenceMatcherHelper
class SequenceMatcher
{
/**
* @var string|array Either a string or an array containing a callback function to determine
Expand Down Expand Up @@ -258,15 +259,15 @@ public function findLongestMatch(int $aLower, int $aUpper, int $bLower, int $bUp

for ($i = $aLower; $i < $aUpper; ++$i) {
$newJ2Len = [];
$jDict = $this->arrayGetDefault($this->b2j, $old[$i], $nothing);
$jDict = SequenceMatcherHelper::arrayGetDefault($this->b2j, $old[$i], $nothing);
foreach ($jDict as $j) {
if ($j < $bLower) {
continue;
} elseif ($j >= $bUpper) {
break;
}

$k = $this->arrayGetDefault($j2Len, $j - 1, 0) + 1;
$k = SequenceMatcherHelper::arrayGetDefault($j2Len, $j - 1, 0) + 1;
$newJ2Len[$j] = $k;
if ($k > $bestSize) {
$bestI = $i - $k + 1;
Expand Down Expand Up @@ -413,7 +414,7 @@ public function getMatchingBlocks(): array
usort(
$matchingBlocks,
function ($aArray, $bArray) {
return $this->tupleSort($aArray, $bArray);
return SequenceMatcherHelper::tupleSort($aArray, $bArray);
}
);

Expand Down