Code Duplication    Length = 27-34 lines in 2 locations

core/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php 2 locations

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