Code Duplication    Length = 25-26 lines in 3 locations

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

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

src/Phinx/Db/Adapter/PostgresAdapter.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
                    tc.constraint_name,
638
                    tc.table_name, kcu.column_name,
639
                    ccu.table_name AS referenced_table_name,
640
                    ccu.column_name AS referenced_column_name
641
                FROM
642
                    information_schema.table_constraints AS tc
643
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
644
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
645
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
646
                ORDER BY kcu.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/SqlServerAdapter.php 1 location

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