Code Duplication    Length = 25-26 lines in 3 locations

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

@@ 633-657 (lines=25) @@
630
     * @param string $tableName Table Name
631
     * @return array
632
     */
633
    protected function getForeignKeys($tableName)
634
    {
635
        $foreignKeys = [];
636
        $rows = $this->fetchAll(sprintf(
637
            "SELECT
638
              CONSTRAINT_NAME,
639
              TABLE_NAME,
640
              COLUMN_NAME,
641
              REFERENCED_TABLE_NAME,
642
              REFERENCED_COLUMN_NAME
643
            FROM information_schema.KEY_COLUMN_USAGE
644
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
645
              AND REFERENCED_TABLE_NAME IS NOT NULL
646
              AND TABLE_NAME = '%s'
647
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
648
            $tableName
649
        ));
650
        foreach ($rows as $row) {
651
            $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME'];
652
            $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME'];
653
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME'];
654
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
655
        }
656
657
        return $foreignKeys;
658
    }
659
660
    /**

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

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

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

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