Code Duplication    Length = 27-34 lines in 2 locations

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

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