Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Differ.php

function Differ::extractDiff

Same name in this branch
  1. 11.1.x vendor/phpstan/phpdoc-parser/src/Printer/Differ.php \PHPStan\PhpDocParser\Printer\Differ::extractDiff()

Parameters

array<int, array<int, int>> $trace:

T[] $old:

T[] $new:

Return value

DiffElem[]

1 call to Differ::extractDiff()
Differ::diff in vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php
Calculate diff (edit script) from $old to $new.

File

vendor/nikic/php-parser/lib/PhpParser/Internal/Differ.php, line 98

Class

Differ
Implements the Myers diff algorithm.

Namespace

PhpParser\Internal

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal