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

@@ 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}