Code Duplication    Length = 25-32 lines in 2 locations

lib/Doctrine/DBAL/Schema/Comparator.php 2 locations

@@ 320-344 (lines=25) @@
317
     *
318
     * @return void
319
     */
320
    private function detectColumnRenamings(TableDiff $tableDifferences)
321
    {
322
        $renameCandidates = [];
323
        foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) {
324
            foreach ($tableDifferences->removedColumns as $removedColumn) {
325
                if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) {
326
                    $renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName];
327
                }
328
            }
329
        }
330
331
        foreach ($renameCandidates as $candidateColumns) {
332
            if (count($candidateColumns) == 1) {
333
                list($removedColumn, $addedColumn) = $candidateColumns[0];
334
                $removedColumnName = strtolower($removedColumn->getName());
335
                $addedColumnName = strtolower($addedColumn->getName());
336
337
                if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) {
338
                    $tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
339
                    unset($tableDifferences->addedColumns[$addedColumnName]);
340
                    unset($tableDifferences->removedColumns[$removedColumnName]);
341
                }
342
            }
343
        }
344
    }
345
346
    /**
347
     * Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop
@@ 354-385 (lines=32) @@
351
     *
352
     * @return void
353
     */
354
    private function detectIndexRenamings(TableDiff $tableDifferences)
355
    {
356
        $renameCandidates = [];
357
358
        // Gather possible rename candidates by comparing each added and removed index based on semantics.
359
        foreach ($tableDifferences->addedIndexes as $addedIndexName => $addedIndex) {
360
            foreach ($tableDifferences->removedIndexes as $removedIndex) {
361
                if (! $this->diffIndex($addedIndex, $removedIndex)) {
362
                    $renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName];
363
                }
364
            }
365
        }
366
367
        foreach ($renameCandidates as $candidateIndexes) {
368
            // If the current rename candidate contains exactly one semantically equal index,
369
            // we can safely rename it.
370
            // Otherwise it is unclear if a rename action is really intended,
371
            // therefore we let those ambiguous indexes be added/dropped.
372
            if (count($candidateIndexes) === 1) {
373
                list($removedIndex, $addedIndex) = $candidateIndexes[0];
374
375
                $removedIndexName = strtolower($removedIndex->getName());
376
                $addedIndexName = strtolower($addedIndex->getName());
377
378
                if (! isset($tableDifferences->renamedIndexes[$removedIndexName])) {
379
                    $tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex;
380
                    unset($tableDifferences->addedIndexes[$addedIndexName]);
381
                    unset($tableDifferences->removedIndexes[$removedIndexName]);
382
                }
383
            }
384
        }
385
    }
386
387
    /**
388
     * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key1