Hal\MutaTesting\Diff\DiffHtml::diff PHP Method

diff() public method

Returns the diff between two arrays or strings as string.
public diff ( array | string $from, array | string $to ) : string
$from array | string
$to array | string
return string
    public function diff($from, $to)
    {
        $tool = new \SebastianBergmann\Diff('');
        $buffer = '';
        $diff = $tool->diffToArray($from, $to);
        $inOld = FALSE;
        $i = 0;
        $old = array();
        foreach ($diff as $line) {
            if ($line[1] === 0) {
                if ($inOld === FALSE) {
                    $inOld = $i;
                }
            } else {
                if ($inOld !== FALSE) {
                    if ($i - $inOld > 5) {
                        $old[$inOld] = $i - 1;
                    }
                    $inOld = FALSE;
                }
            }
            ++$i;
        }
        $start = isset($old[0]) ? $old[0] : 0;
        $end = count($diff);
        if ($tmp = array_search($end, $old)) {
            $end = $tmp;
        }
        $newChunk = TRUE;
        for ($i = $start; $i < $end; $i++) {
            if (isset($old[$i])) {
                $buffer .= "<br />";
                $newChunk = TRUE;
                $i = $old[$i];
            }
            if ($newChunk) {
                //                $buffer .= "@@ @@\n";
                $newChunk = FALSE;
            }
            if ($diff[$i][1] === 1) {
                $buffer .= '<span style="background-color:#DFF0D8;">' . $this->highlight($diff[$i][0]) . "</span><br />";
            } else {
                if ($diff[$i][1] === 2) {
                    $buffer .= '<span style="background-color:#F2DEDE;">' . $this->highlight($diff[$i][0]) . "</span><br />";
                } else {
                    $buffer .= ' ' . $this->highlight($diff[$i][0]) . "<br />";
                }
            }
        }
        return $buffer;
    }