Looks through a line to find the character to of the first difference between the 2 strings.

If no difference is found, returns -1

@param string $old
@param string $new

@return int
15099
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;
        }

        for ($i = 0; $i < $oldLen && $i < $newLen; $i++) {
            if (mb_substr($old, $i, 1) !== mb_substr($new, $i, 1)) {
                return $i;
            }
        }
        if ($i < $oldLen || $i < $newLen) {
            return $i;
        }
        return -1;
    }
542120
public function replace($old, $new): self
    {
        Assert::typeOf(['string', __CLASS__], $old, $new);

        return new static(str_replace((string) $old, (string) $new, $this->data), $this->encoding);
    }
1269693
private function compareBcStrings(string $a, string $b) : int
    {
        $a_len = strlen($a);
        $b_len = strlen($b);

        if ($a_len > $b_len) {
            return -1;
        }

        if ($a_len < $b_len) {
            return 1;
        }

        $a_len = strlen(str_replace(['*', '?'], '', $a));
        $b_len = strlen(str_replace(['*', '?'], '', $b));

        if ($a_len > $b_len) {
            return -1;
        }

        if ($a_len < $b_len) {
            return 1;
        }

        return 0;
    }
1238959
public function renameColumn($old, $new)
    {
        $this->append(sprintf(' RENAME COLUMN %s TO %s ', $this->quote($old), $this->quote($new)));
        return $this;
    }
909714
public static function mergeStatic($new = null, array $old = [])
    {
        // Parses the string into an associative array
        parse_str(preg_replace('/\s*([\w-]+)\s*=\s*"([^"]+)"/', '$1=$2&', $new), $attrs);

        // Merge classes
        $attrs['class'] = self::formatGroupClass($attrs, $old);

        // Merging new and old array and parse it as a string
        return self::attributes(array_merge(Arr::except($old, array('class')), $attrs));
    }
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;
    }
362823
protected function mergeConfigs(array $old, array $new) : array
    {
      foreach ($new as $key => $val) {
        if (!array_key_exists($key, $old) || !is_array($old[$key]) || !is_array($val)) {
          $old[$key] = $val;
          continue;
        }

        if (is_int($key)) {
          $old[] = $val;
          continue;
        }

        $old[$key] = $this->mergeConfigs($old[$key], $val);
      }

      return $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;
    }
1105726
public function rename($new, $old = null)
    {
        $this->arguments[] = 'rename';
        if ($old) {
            $this->arguments[] = $old;
        }
        $this->arguments[] = $new;
        return $this;
    }
1011933
protected static function formatGroupPrefix($new, $old)
    {
        $oldPrefix = $old['prefix'] ?? null;

        if (isset($new['prefix'])) {
            return \trim($oldPrefix, '/').'/'.\trim($new['prefix'], '/');
        }

        return $oldPrefix;
    }
379508
public static function formatGroupClass($new, $old)
    {
        if (isset($new['class'])) {
            $classes = trim(trim(array_get($old, 'class')).' '.trim(array_get($new, 'class')));

            return implode(' ', array_unique(explode(' ', $classes)));
        }

        return array_get($old, 'class');
    }
966216
public function callbackChangeSortIndex($new, $old)
    {
        // get old position
        $newPos = (new Query)->select([$this->sortIndexFieldName])->from($this->refTableName)->where([$this->imageIdFieldName => $new['originalImageId']])->scalar();
        $oldPos = (new Query)->select([$this->sortIndexFieldName])->from($this->refTableName)->where([$this->imageIdFieldName => $old['originalImageId']])->scalar();
        
        // switch positions
        $changeNewPos = Yii::$app->db->createCommand()->update($this->refTableName, [$this->sortIndexFieldName => $oldPos], [
            $this->imageIdFieldName => $new['originalImageId'],
            $this->refFieldName => $this->itemId,
        ])->execute();
        
        $changeOldPos = Yii::$app->db->createCommand()->update($this->refTableName, [$this->sortIndexFieldName => $newPos], [
            $this->imageIdFieldName => $old['originalImageId'],
            $this->refFieldName => $this->itemId,
        ])->execute();
        
        return true;
    }
1042424
protected function getForeignKeysMigrations($new = [], $old = [])
    {
        if (empty($new['tables'])) {
            return [];
        }
        $output = [];
        foreach ($new['tables'] as $tableId => $newTable) {
            if ($newTable['table']['table_name'] === $this->options['default_migration_table']) {
                continue;
            }
            $oldTable = $old['tables'][$tableId];

            if (!empty($oldTable['foreign_keys'])) {
                foreach ($oldTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($newTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyRemove($tableId, $fkName);
                    }
                }
            }
            if (!empty($newTable['foreign_keys'])) {
                foreach ($newTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($oldTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyCreate($tableId, $fkName);
                    }
                }
            }
        }

        return $output;
    }
106403
private function diffRecords($old, $new)
	{
		$diff = Set::diff($old, $new);
		$formatted = array();

		foreach ($diff as $key => $value) {
			if (!isset($old[$key]) || !isset($new[$key])) {
				continue;
			}

			$formatted[$key] = array('old' => $old[$key], 'new' => $new[$key]);
		}

		return $formatted;
	}
652425
public function mergeConditionAttribute( $old, $new ) {
		try {
			$condition = $this->condition_factory->merge( $old, $new );
		} catch ( ConfigurationException $e ) {
			throw new ConfigurationException( 'Route condition is not a valid route string or condition.' );
		}

		return $condition;
	}
320386
public static function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = self::merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
669149
public function compareIndexes(Index $oldIndex, Index $newIndex)
    {
        return ($oldIndex->getName() !== $newIndex->getName())
            || ($oldIndex->getColumnNames() !== $newIndex->getColumnNames())
            || ($oldIndex->isUnique() !== $newIndex->isUnique());
    }