Code Duplication    Length = 25-26 lines in 3 locations

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

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

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

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