@param \ViKon\Diff\Text $old
@param \ViKon\Diff\Text $new

@return array
519666
private function buildDiffTable(Text $old, Text $new) {
        $diffTable = [array_fill(0, count($new) + 1, 0)];
        for ($row = 1; $row <= count($old); $row++) {
            $diffTable[$row] = [0];
            for ($col = 1; $col <= count($new); $col++) {
                $diffTable[$row][$col] = $old[$row - 1] === $new[$col - 1]
                    ? $diffTable[$row - 1][$col - 1] + 1
                    : max($diffTable[$row - 1][$col], $diffTable[$row][$col - 1]);
            }
        }

        return $diffTable;
    }
1217052
public static function mergeGroup($new, $old)
	{
		$new['namespace'] = static::formatUsesPrefix($new, $old);

		$new['prefix'] = static::formatGroupPrefix($new, $old);

		if (isset($new['domain'])) unset($old['domain']);

		return array_merge_recursive(array_except($old, array('namespace', 'prefix')), $new);
	}
745596
public function diffHtml($old, $new, $output = 'array')
    {
        if (!in_array($output, ['array', 'string'])) {
            throw new \RuntimeException(
                sprintf('Unknown output type "%s"', $output)
            );
        }

        $ret = '';
        $arr = [
            'old' => '',
            'new' => '',
        ];

        $diff = $this->diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));

        //die(print_r($diff));
        foreach ($diff as $k) {
            if (is_array($k)) {
                $deletions  = !empty($k['d']) ? '<del>'.implode(' ', $k['d']).'</del>' : '';
                $insertions = !empty($k['i']) ? '<ins>'.implode(' ', $k['i']).'</ins>' : '';
                $deletions  = $deletions.(!empty($deletions) ? ' ' : '');
                $insertions = $insertions.(!empty($insertions) ? ' ' : '');
                $ret .= trim($deletions).$insertions;
                $arr['old'] .= $deletions;
                $arr['new'] .= $insertions;
            } else {
                // No differences
                $str = $k.' ';
                $ret .= $str;
                $arr['old'] .= $str;
                $arr['new'] .= $str;
            }
        }

        // cleanup
        $ret        = trim(ltrim($ret));
        $arr['old'] = trim(ltrim($arr['old']));
        $arr['new'] = trim(ltrim($arr['new']));

        return ($output === 'string') ? $ret : $arr;
    }
22044
protected function formatNamespace(array $new, array $old)
    {
        if (isset($new['namespace']) && isset($old['namespace'])) {
            return trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\');
        } elseif (isset($new['namespace'])) {
            return trim($new['namespace'], '\\');
        }

        return array_get($old, 'namespace');
    }
272345
protected function formatNamespace(array $new, array $old)
    {
        if (isset($new['namespace']) && isset($old['namespace'])) {
            return trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\');
        } elseif (isset($new['namespace'])) {
            return trim($new['namespace'], '\\');
        }

        return Arr::get($old, 'namespace');
    }
772774
public function update($old, $new): bool
    {
        if ($this->hasNot($old)) {
            return false;
        }

        $this->set($old, $new);

        return true;
    }
1320698
protected static function formatPrefix($new, $old)
    {
        $old = $old['prefix'] ?? null;

        return isset($new['prefix']) ? trim($old, '/').'/'.trim($new['prefix'], '/') : $old;
    }
1055482
protected function updateLogo( $new, $old )
    {
        $this->removeFile( $old );
        $new = $this->addFile( $new, 'settings/logo.%2$s' );
        $this->setSetting( 'logoType', $this->getMime( $new ) );
        return $new;
    }
335385
protected function rollback(array $old, array $new)
    {
        foreach ($old as $key => $value) {
            $current = $this->cache->get($key, $token);

            /*
             * If the value right now equals the one we planned to write, it
             * should be restored to what it was before. If it's yet something
             * else, another process must've stored it and we should leave it
             * alone.
             */
            if ($current === $new) {
                /*
                 * CAS the rollback. If it fails, that means another process
                 * has stored in the meantime and we can just leave it alone.
                 * Note that we can't know the original expiration time!
                 */
                $this->cas($token, $key, $value, 0);
            }
        }

        $this->clear();
    }
312067
public function firstDifference($old, $new)
    {
        // loop through old and new character by character and compare
        $oldLen = mb_strlen($old);
        $newLen = mb_strlen($new);

        if ($oldLen === 0) {
            return 0;
        }

        $oldStripped = $this->cursor->filter($old, static::REPLACEMENT_CHAR);
        $newStripped = $this->cursor->filter($new, static::REPLACEMENT_CHAR);
        $lastReal = 0;

        for ($i = 0; $i < $oldLen && $i < $newLen; $i++) {
            if (mb_substr($old, $i, 1) !== mb_substr($new, $i, 1)) {
                if (($i > 0)
                    && ((mb_substr($oldStripped, $i - 1, 1) === static::REPLACEMENT_CHAR)
                        || (mb_substr($newStripped, $i - 1, 1) === static::REPLACEMENT_CHAR)
                    )
                ) {
                    return $lastReal > 0 ? $lastReal + 1 : 0;
                }
                return $i;
            } elseif (mb_substr($oldStripped, $i, 1) !== static::REPLACEMENT_CHAR) {
                $lastReal = $i;
            }
        }
        if ($i < $oldLen || $i < $newLen) {
            return $i;
        }
        return -1;
    }
147514
public function getTableMigration($output, $new, $old)
    {
        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetUniqueChecks(0);
            $output[] = $this->getSetForeignKeyCheck(0);
        }

        $output = $this->getTableMigrationNewDatabase($output, $new, $old);
        $output = $this->getTableMigrationNewTables($output, $new, $old);

        if (!empty($this->options['foreign_keys'])) {
            $lines = $this->getForeignKeysMigrations($new, $old);
            $output = $this->appendLines($output, $lines);
        }

        $output = $this->getTableMigrationOldTables($output, $new, $old);

        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetForeignKeyCheck(1);
            $output[] = $this->getSetUniqueChecks(1);
        }

        return $output;
    }
513419
protected function getTableMigrationDropTables(array $output, array $new, array $old): array
    {
        if (empty($old['tables'])) {
            return $output;
        }

        foreach ($old['tables'] as $tableName => $table) {
            if ($tableName === $this->options['default_migration_table']) {
                continue;
            }

            if (!isset($new['tables'][$tableName])) {
                $output[] = $this->getDropTable($tableName);
                continue;
            }
        }

        return $output;
    }
484104
public function compare(Column $oldColumn, Column $newColumn)
    {
        $differences = array();

        if ($oldColumn->getType() !== $newColumn->getType()) {
            $differences[] = 'type';
        }

        if ($oldColumn->getLength() !== $newColumn->getLength()) {
            $differences[] = 'length';
        }

        if ($oldColumn->getPrecision() !== $newColumn->getPrecision()) {
            $differences[] = 'precision';
        }

        if ($oldColumn->getScale() !== $newColumn->getScale()) {
            $differences[] = 'scale';
        }

        if ($oldColumn->isUnsigned() !== $newColumn->isUnsigned()) {
            $differences[] = 'unsigned';
        }

        if ($oldColumn->isFixed() !== $newColumn->isFixed()) {
            $differences[] = 'fixed';
        }

        if ($oldColumn->isNotNull() !== $newColumn->isNotNull()) {
            $differences[] = 'not_null';
        }

        if ($oldColumn->getDefault() !== $newColumn->getDefault()) {
            $differences[] = 'default';
        }

        if ($oldColumn->isAutoIncrement() !== $newColumn->isAutoIncrement()) {
            $differences[] = 'auto_increment';
        }

        if ($oldColumn->getComment() !== $newColumn->getComment()) {
            $differences[] = 'comment';
        }

        return new ColumnDiff($oldColumn, $newColumn, $differences);
    }
799974
protected function auditDeletedAttributes(array &$old, array &$new)
    {
        foreach ($this->attributes as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = $value;
            }
        }
    }
393202
protected function compaireSecondary($old, $new)
    {
        $oldMajor = dot($old)[0];
        $newMajor = dot($new)[0];

        $oldMinor = dot($old)[1];
        $newMinor = dot($new)[1];

        $oldSecondary = dot($old)[2];
        $newSecondary = dot($new)[2];

        return $oldSecondary != $newSecondary && $oldMajor == $newMajor && $oldMinor == $newMinor;
    }
656633
public function replaceFile($old, $new, array $content)
    {
        $oldFileContent = file_get_contents($old);
        file_put_contents($new, vsprintf($oldFileContent, $content));
        unlink($old);
    }
1084646
protected static function formatUsesPrefix($new, $old)
    {
        if (isset($new['namespace'])) {
            return isset($old['namespace']) && \strpos($new['namespace'], '\\') !== 0
                ? \trim($old['namespace'], '\\').'\\'.\trim($new['namespace'], '\\')
                : \trim($new['namespace'], '\\');
        }

        return $old['namespace'] ?? null;
    }