function Differ::extractDiff
Same name in this branch
- 11.1.x vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php \PhpParser\Internal\Differ::extractDiff()
*
Parameters
array<int, array<int, int>> $trace: * @param T[] $old * @param T[] $new * @return DiffElem[]
1 call to Differ::extractDiff()
- Differ::diff in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Differ.php - * Calculate diff (edit script) from $old to $new. * *
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Differ.php, line 111
Class
Namespace
PHPStan\PhpDocParser\PrinterCode
private function extractDiff(array $trace, int $x, int $y, array $old, array $new) : array {
$result = [];
for ($d = count($trace) - 1; $d >= 0; $d--) {
$v = $trace[$d];
$k = $x - $y;
if ($k === -$d || $k !== $d && $v[$k - 1] < $v[$k + 1]) {
$prevK = $k + 1;
}
else {
$prevK = $k - 1;
}
$prevX = $v[$prevK];
$prevY = $prevX - $prevK;
while ($x > $prevX && $y > $prevY) {
$result[] = new DiffElem(DiffElem::TYPE_KEEP, $old[$x - 1], $new[$y - 1]);
$x--;
$y--;
}
if ($d === 0) {
break;
}
while ($x > $prevX) {
$result[] = new DiffElem(DiffElem::TYPE_REMOVE, $old[$x - 1], null);
$x--;
}
while ($y > $prevY) {
$result[] = new DiffElem(DiffElem::TYPE_ADD, null, $new[$y - 1]);
$y--;
}
}
return array_reverse($result);
}