Eloquent\Phony\Difference\DifferenceSequenceMatcher::getOpCodes PHP Method

getOpCodes() public method

The nested array returned contains an array describing the opcode which includes: 0 - The type of tag (as described below) for the opcode. 1 - The beginning line in the first sequence. 2 - The end line in the first sequence. 3 - The beginning line in the second sequence. 4 - The end line in the second sequence. The different types of tags include: replace - The string from $i1 to $i2 in $a should be replaced by the string in $b from $j1 to $j2. delete - The string in $a from $i1 to $j2 should be deleted. insert - The string in $b from $j1 to $j2 should be inserted at $i1 in $a. equal - The two strings with the specified ranges are equal.
public getOpCodes ( ) : array
return array Array of the opcodes describing the differences between the strings.
    public function getOpCodes()
    {
        $i = 0;
        $j = 0;
        $opCodes = array();
        $blocks = $this->getMatchingBlocks();
        foreach ($blocks as $block) {
            list($ai, $bj, $size) = $block;
            $tag = '';
            if ($i < $ai && $j < $bj) {
                $tag = 'replace';
            } elseif ($i < $ai) {
                $tag = 'delete';
            } elseif ($j < $bj) {
                $tag = 'insert';
            }
            if ($tag) {
                $opCodes[] = array($tag, $i, $ai, $j, $bj);
            }
            $i = $ai + $size;
            $j = $bj + $size;
            if ($size) {
                $opCodes[] = array('equal', $ai, $i, $bj, $j);
            }
        }
        return $opCodes;
    }