Code Duplication    Length = 25-26 lines in 3 locations

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

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

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

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

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

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