@param array $diff

@return array
189145
public static function convertJsonPatchToMongoUpdate(array $diff, array $values)
    {
        $update = ['$set' => [], '$unset' => [], '$push' => []];

        $arrayFullReset = [];

        foreach ($diff as $op) {
            if (isset($op['path']) && '/_id' == $op['path']) {
                continue;
            }

            switch ($op['op']) {
                case 'add':
                    if (static::isPathArray($op['path'])) {
                        if (false == isset($update['$push'][self::pathToDotWithoutLastPart($op['path'])]['$each'])) {
                            $update['$push'][self::pathToDotWithoutLastPart($op['path'])]['$each'] = [];
                        }

                        $update['$push'][self::pathToDotWithoutLastPart($op['path'])]['$each'][] = $op['value'];
                    } else if (is_array($op['value']) && array_key_exists(0, $op['value'])) {
                        $update['$set'][self::pathToDot($op['path'])] = $op['value'];
                    } else if (is_array($op['value'])) {
                        foreach ($op['value'] as $key => $value) {
                            $update['$set'][self::pathToDot($op['path']) . '.' . $key] = $value;
                        }
                    } else {
                        $update['$set'][self::pathToDot($op['path'])] = $op['value'];
                    }

                    break;
                case 'remove':
                    // fix for  https://jira.mongodb.org/browse/SERVER-1014
                    if (static::isPathArray($op['path'])) {
                        $dotPath = self::pathToDotWithoutLastPart($op['path']);
                        if (array_key_exists($dotPath, $arrayFullReset)) {
                            continue;
                        }

                        $update['$set'][$dotPath] = array_get($dotPath, [], $values);

                        $arrayFullReset[$dotPath] = true;
                    } else {
                        $update['$unset'][self::pathToDot($op['path'])] = '';
                    }

                    break;
                case 'replace':
                    $update['$set'][self::pathToDot($op['path'])] = $op['value'];

                    break;
                default:
                    throw new \LogicException('JSON Patch operation "'.$op['op'].'"" is not supported.');
            }
        }

        foreach (array_keys($arrayFullReset) as $arrayResetPath) {
            foreach (array_keys($update['$set']) as $setPath) {
                if ($setPath === $arrayResetPath) {
                    continue;
                }

                if (0 === strpos($setPath, $arrayResetPath)) {
                    unset($update['$set'][$setPath]);
                }
            }
        }

        foreach (array_keys($arrayFullReset) as $arrayResetPath) {
            foreach (array_keys($update['$push']) as $pushPath) {
                if (0 === strpos($pushPath, $arrayResetPath)) {
                    unset($update['$push'][$pushPath]);
                }
            }
        }

        foreach (array_keys($arrayFullReset) as $arrayResetPath) {
            foreach (array_keys($update['$unset']) as $setPath) {
                if (0 === strpos($setPath, $arrayResetPath)) {
                    unset($update['$unset'][$setPath]);
                }
            }
        }

        if (empty($update['$push'])) {
            unset($update['$push']);
        }

        if (empty($update['$set'])) {
            unset($update['$set']);
        }
        if (empty($update['$unset'])) {
            unset($update['$unset']);
        }

        return $update;
    }
47365
function format($diff) {

    	$xi = $yi = 1;
    	$block = false;
    	$context = array();

    	$nlead = $this->leading_context_lines;
    	$ntrail = $this->trailing_context_lines;

    	$this->_start_diff();

    	foreach ($diff->edits as $edit) {
    		if ($edit->type == 'copy') {
    			if (is_array($block)) {
    				if (sizeof($edit->orig) <= $nlead + $ntrail) {
    					$block[] = $edit;
    				}
    				else{
    					if ($ntrail) {
    						$context = array_slice($edit->orig, 0, $ntrail);
    						$block[] = new _WikiWikiDiffOp_Copy($context);
    					}
    					$this->_block($x0, $ntrail + $xi - $x0,
    								  $y0, $ntrail + $yi - $y0,
    								  $block);
    					$block = false;
    				}
    			}
    			$context = $edit->orig;
    		}
    		else {
    			if (! is_array($block)) {
    				$context = array_slice($context, sizeof($context) - $nlead);
    				$x0 = $xi - sizeof($context);
    				$y0 = $yi - sizeof($context);
    				$block = array();
    				if ($context)
    					$block[] = new _WikiWikiDiffOp_Copy($context);
    			}
    			$block[] = $edit;
    		}

    		if ($edit->orig)
    			$xi += sizeof($edit->orig);
    		if ($edit->closing)
    			$yi += sizeof($edit->closing);
    	}

    	if (is_array($block))
    		$this->_block($x0, $xi - $x0,
    					  $y0, $yi - $y0,
    					  $block);

    	return $this->_end_diff();
    }
1091497
private static function coalesceReplacements(array $diff)
    {
        $newDiff = [];
        $c = \count($diff);
        for ($i = 0; $i < $c; $i++) {
            $diffType = $diff[$i]->type;
            if ($diffType !== DiffElem::TYPE_REMOVE) {
                $newDiff[] = $diff[$i];
                continue;
            }

            $j = $i;
            while ($j < $c && $diff[$j]->type === DiffElem::TYPE_REMOVE) {
                $j++;
            }

            $k = $j;
            while ($k < $c && $diff[$k]->type === DiffElem::TYPE_ADD) {
                $k++;
            }

            if ($j - $i === $k - $j) {
                $len = $j - $i;
                for ($n = 0; $n < $len; $n++) {
                    $newDiff[] = new DiffElem(
                        DiffElem::TYPE_REPLACE,
                        $diff[$i + $n]->old,
                        $diff[$j + $n]->new
                    );
                }
            } else {
                for (; $i < $k; $i++) {
                    $newDiff[] = $diff[$i];
                }
            }

            /** @psalm-suppress LoopInvalidation */
            $i = $k - 1;
        }
        return $newDiff;
    }
30939
function postProcessDiff( $diffArray )
    {
        $string = "";
        $diff = array();
        $item = current( $diffArray );

        $lastStatus = $item['status'];

        $mode = array( 0 => 'unchanged',
                       1 => 'removed',
                       2 => 'added' );

        while ( $item = current( $diffArray ) )
        {
            if ( $item['status'] != $lastStatus )
            {
                $diff[] = array( $mode[$lastStatus] => $string,
                                 'status' => $lastStatus );
                $lastStatus = $item['status'];
                $string ="";
                continue;
            }

            $string .= $item[$mode[$lastStatus]] . " ";
            next( $diffArray );
        }
        if ( strlen( $string ) > 0 )
        {
            $diff[] = array( $mode[$lastStatus] => $string,
                             'status' => $lastStatus );
        }
        return $diff;
    }
832421
private function collectIndexes(TableDiff $tableDiff)
    {
        foreach ($tableDiff->getCreatedIndexes() as $index) {
            $this->createIndexQueries = array_merge(
                $this->createIndexQueries,
                $this->platform->getCreateIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
            );
        }

        foreach ($tableDiff->getDroppedIndexes() as $index) {
            $this->dropIndexQueries = array_merge(
                $this->dropIndexQueries,
                $this->platform->getDropIndexSQLQueries($index, $tableDiff->getNewAsset()->getName())
            );
        }
    }
326312
function diff($arr) {
        if($arr instanceof self) {
            $arr = $arr->all();
        }
        
        return (new self(\array_diff($this->data, $arr)));
    }
398081
private function removeTrailingWhitespaces(string $diff): string
    {
        $diff = Strings::replace($diff, '#( ){1,}\n#', PHP_EOL);

        return rtrim($diff);
    }
1326993
public function getMergedData(array $base, array $diff_res)
    {
        $res = $base + $diff_res[self::ADD];
        $res = array_diff_key($res, $diff_res[self::DEL]);
        foreach ($diff_res[self::UPDATE] as $field_id => $values) {
            $new_values = array_merge($values[self::BASE], $values[self::MODIFIED]);
            $res[$field_id] = $new_values;
        }
        return $res;
    }
945246
private function getAddedColumns($tableName, TableDiff $diff)
    {
        /** @var $col \Doctrine\DBAL\Schema\Column */
        foreach ($diff->addedColumns as $col) {
            $this->addMessage($tableName, sprintf('missing column `%s`', $col->getName()));
        }
    }
177131
public function generateQueries(array $diff_res)
    {
        $queries = array();
        foreach ($diff_res[self::ADD] as $new_field) {
            $queries[] = $this->createAddQuery($new_field);
        }
        foreach ($diff_res[self::DEL] as $del_field) {
            $queries[] = $this->createDeleteQuery($del_field);
        }
        foreach ($diff_res[self::UPDATE] as $mod_field) {
            $queries[] = $this->createUpdateQuery($mod_field);
        }
        return $queries;
    }
1209356
private function getChangedColumns($tableName, TableDiff $diff)
    {
        /** @var $col \Doctrine\DBAL\Schema\ColumnDiff */
        foreach ($diff->changedColumns as $col) {
            $this->addMessage($tableName, sprintf('invalid column `%s`', $col->oldColumnName));
        }
    }
5834
protected function parseFileDiff(\Arbit\VCSWrapper\Diff\Collection $diff, array $lines)
    {
        $chunks = array();
        while (count($lines)) {
            // Skip lines until we hit a range specification
            while (!preg_match('(^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@)', $last = array_shift($lines), $match)) {
                // If we reached the end, break
                if ($last === null) {
                    break 2;
                }
            }

            $chunk = new \Arbit\VCSWrapper\Diff\Chunk(
                $match['start'],
                (isset($match['startrange']) ? max(1, $match['startrange']) : 1),
                $match['end'],
                (isset($match['endrange']) ? max(1, $match['endrange']) : 1)
            );

            // Read following diff lines
            $diffLines = array();
            $last      = null;
            while (count($lines) &&
                    (preg_match('(^(?P<type>[+ -])(?P<line>.*))', $last = array_shift($lines), $match) ||
                      (strpos($last, '\\ No newline at end of file') === 0)))
            {
                // We ignore the missing newlines for now
                if (count($match)) {
                    $diffLines[] = new \Arbit\VCSWrapper\Diff\Line(
                        ($match['type'] === '+' ? \Arbit\VCSWrapper\Diff\Line::ADDED :
                            ($match['type'] === '-' ? \Arbit\VCSWrapper\Diff\Line::REMOVED : \Arbit\VCSWrapper\Diff\Line::UNCHANGED)),
                        $match['line']
                    );
                }
            }
            $chunk->lines = $diffLines;
            $chunks[]     = $chunk;

            // Repreprend last not matching line
            if ($last !== null) {
                array_unshift($lines, $last);
            }
        }

        $diff->chunks = $chunks;
    }
813858
private function getChangedForeignKeys($tableName, TableDiff $diff)
    {
        foreach ($diff->changedForeignKeys as $foreignKey) {
            $this->addForeignKeysMessage($tableName, $foreignKey, 'changed foreign key on `%s`, it is now related to `%s.%s`');
        }
    }
662860
public function getChangelog($diff = null)
    {
        if (!$diff) {
            return $this->data['changelog'];
        }

        $diffLog = [];
        foreach ((array)$this->data['changelog'] as $version => $changelog) {
            preg_match("/[\w\-\.]+/", $version, $cleanVersion);

            if (!$cleanVersion || version_compare($diff, $cleanVersion[0], '>=')) {
                continue;
            }

            $diffLog[$version] = $changelog;
        }

        return $diffLog;
    }
1283747
public function getModifyTableColumnsDDL(TableDiff $tableDiff)
    {
        $ret = '';

        foreach ($tableDiff->getRemovedColumns() as $column) {
            $ret .= $this->getRemoveColumnDDL($column);
        }

        foreach ($tableDiff->getRenamedColumns() as $columnRenaming) {
            $ret .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]);
        }

        if ($modifiedColumns = $tableDiff->getModifiedColumns()) {
            $ret .= $this->getModifyColumnsDDL($modifiedColumns);
        }

        if ($addedColumns = $tableDiff->getAddedColumns()) {
            $ret .= $this->getAddColumnsDDL($addedColumns);
        }

        return $ret;
    }
25952
private function getRenamedColumns($tableName, TableDiff $diff)
    {
        foreach (array_keys($diff->renamedColumns) as $colName) {
            $this->addMessage($tableName, sprintf('renamed column `%s`', $colName));
        }
    }
606362
public function diff(array $values)
    {
        $copy = $this->withData($values);
        return array_diff_assoc($copy->toArray(), $this->toArray());
    }