function DiffOpOutputBuilder::hunkOp

Same name in other branches
  1. 10 core/lib/Drupal/Component/Diff/DiffOpOutputBuilder.php \Drupal\Component\Diff\DiffOpOutputBuilder::hunkOp()

Returns the proper DiffOp object based on the hunk mode.

@throw \InvalidArgumentException When $mode is not valid.

Parameters

int $mode: A Differ constant or self::CHANGED.

string[] $source: An array of strings to be changed/added/removed/copied.

string[] $source: The array of strings to be changed to when self::CHANGED is specified.

Return value

\Drupal\Component\Diff\Engine\DiffOp A DiffOp* value object.

1 call to DiffOpOutputBuilder::hunkOp()
DiffOpOutputBuilder::toOpsArray in core/lib/Drupal/Component/Diff/DiffOpOutputBuilder.php
Converts the output of Differ to an array of DiffOp* value objects.

File

core/lib/Drupal/Component/Diff/DiffOpOutputBuilder.php, line 112

Class

DiffOpOutputBuilder
Returns a diff as an array of DiffOp operations.

Namespace

Drupal\Component\Diff

Code

private function hunkOp(int $mode, array $source, array $target) : DiffOp {
    switch ($mode) {
        case Differ::OLD:
            return new DiffOpCopy($source);
        case self::CHANGED:
            return new DiffOpChange($source, $target);
        case Differ::ADDED:
            return new DiffOpAdd($source);
        case Differ::REMOVED:
            return new DiffOpDelete($source);
    }
    throw new \InvalidArgumentException("Invalid \$mode {$mode} specified");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.