Code Duplication    Length = 25-26 lines in 3 locations

src/Phinx/Db/Adapter/PostgresAdapter.php 1 location

@@ 636-660 (lines=25) @@
633
     * @param string $tableName Table Name
634
     * @return array
635
     */
636
    protected function getForeignKeys($tableName)
637
    {
638
        $foreignKeys = [];
639
        $rows = $this->fetchAll(sprintf(
640
            "SELECT
641
                    tc.constraint_name,
642
                    tc.table_name, kcu.column_name,
643
                    ccu.table_name AS referenced_table_name,
644
                    ccu.column_name AS referenced_column_name
645
                FROM
646
                    information_schema.table_constraints AS tc
647
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
648
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
649
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
650
                ORDER BY kcu.position_in_unique_constraint",
651
            $tableName
652
        ));
653
        foreach ($rows as $row) {
654
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
655
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
656
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
657
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
658
        }
659
660
        return $foreignKeys;
661
    }
662
663
    /**

src/Phinx/Db/Adapter/SqlServerAdapter.php 1 location

@@ 762-787 (lines=26) @@
759
     * @param string $tableName Table Name
760
     * @return array
761
     */
762
    protected function getForeignKeys($tableName)
763
    {
764
        $foreignKeys = [];
765
        $rows = $this->fetchAll(sprintf(
766
            "SELECT
767
                    tc.constraint_name,
768
                    tc.table_name, kcu.column_name,
769
                    ccu.table_name AS referenced_table_name,
770
                    ccu.column_name AS referenced_column_name
771
                FROM
772
                    information_schema.table_constraints AS tc
773
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
774
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
775
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
776
                ORDER BY kcu.ordinal_position",
777
            $tableName
778
        ));
779
        foreach ($rows as $row) {
780
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
781
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
782
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
783
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
784
        }
785
786
        return $foreignKeys;
787
    }
788
789
    /**
790
     * {@inheritdoc}

src/Phinx/Db/Adapter/MysqlAdapter.php 1 location

@@ 654-678 (lines=25) @@
651
     * @param string $tableName Table Name
652
     * @return array
653
     */
654
    protected function getForeignKeys($tableName)
655
    {
656
        $foreignKeys = [];
657
        $rows = $this->fetchAll(sprintf(
658
            "SELECT
659
              CONSTRAINT_NAME,
660
              TABLE_NAME,
661
              COLUMN_NAME,
662
              REFERENCED_TABLE_NAME,
663
              REFERENCED_COLUMN_NAME
664
            FROM information_schema.KEY_COLUMN_USAGE
665
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
666
              AND REFERENCED_TABLE_NAME IS NOT NULL
667
              AND TABLE_NAME = '%s'
668
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
669
            $tableName
670
        ));
671
        foreach ($rows as $row) {
672
            $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME'];
673
            $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME'];
674
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME'];
675
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
676
        }
677
678
        return $foreignKeys;
679
    }
680
681
    /**