Code Duplication    Length = 25-26 lines in 3 locations

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

@@ 677-701 (lines=25) @@
674
     * @param string $tableName Table Name
675
     * @return array
676
     */
677
    protected function getForeignKeys($tableName)
678
    {
679
        $foreignKeys = [];
680
        $rows = $this->fetchAll(sprintf(
681
            "SELECT
682
                    tc.constraint_name,
683
                    tc.table_name, kcu.column_name,
684
                    ccu.table_name AS referenced_table_name,
685
                    ccu.column_name AS referenced_column_name
686
                FROM
687
                    information_schema.table_constraints AS tc
688
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
689
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
690
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
691
                ORDER BY kcu.position_in_unique_constraint",
692
            $tableName
693
        ));
694
        foreach ($rows as $row) {
695
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
696
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
697
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
698
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
699
        }
700
701
        return $foreignKeys;
702
    }
703
704
    /**

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

@@ 791-816 (lines=26) @@
788
     * @param string $tableName Table Name
789
     * @return array
790
     */
791
    protected function getForeignKeys($tableName)
792
    {
793
        $foreignKeys = [];
794
        $rows = $this->fetchAll(sprintf(
795
            "SELECT
796
                    tc.constraint_name,
797
                    tc.table_name, kcu.column_name,
798
                    ccu.table_name AS referenced_table_name,
799
                    ccu.column_name AS referenced_column_name
800
                FROM
801
                    information_schema.table_constraints AS tc
802
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
803
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
804
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
805
                ORDER BY kcu.ordinal_position",
806
            $tableName
807
        ));
808
        foreach ($rows as $row) {
809
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
810
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
811
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
812
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
813
        }
814
815
        return $foreignKeys;
816
    }
817
818
    /**
819
     * {@inheritdoc}

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

@@ 620-644 (lines=25) @@
617
     *
618
     * @return array
619
     */
620
    protected function getForeignKeys($tableName)
621
    {
622
        $foreignKeys = [];
623
        $rows        = $this->fetchAll(sprintf(
624
            "SELECT
625
              CONSTRAINT_NAME,
626
              TABLE_NAME,
627
              COLUMN_NAME,
628
              REFERENCED_TABLE_NAME,
629
              REFERENCED_COLUMN_NAME
630
            FROM information_schema.KEY_COLUMN_USAGE
631
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
632
              AND REFERENCED_TABLE_NAME IS NOT NULL
633
              AND TABLE_NAME = '%s'
634
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
635
            $tableName
636
        ));
637
        foreach ($rows as $row) {
638
            $foreignKeys[$row['CONSTRAINT_NAME']]['table']                = $row['TABLE_NAME'];
639
            $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][]            = $row['COLUMN_NAME'];
640
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table']     = $row['REFERENCED_TABLE_NAME'];
641
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
642
        }
643
644
        return $foreignKeys;
645
    }
646
647
    /**