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/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

Differ
Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd49…

Namespace

PHPStan\PhpDocParser\Printer

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