Code Duplication    Length = 25-26 lines in 3 locations

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}

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

@@ 610-634 (lines=25) @@
607
     * @param string $tableName Table Name
608
     * @return array
609
     */
610
    protected function getForeignKeys($tableName)
611
    {
612
        $foreignKeys = [];
613
        $rows = $this->fetchAll(sprintf(
614
            "SELECT
615
              CONSTRAINT_NAME,
616
              TABLE_NAME,
617
              COLUMN_NAME,
618
              REFERENCED_TABLE_NAME,
619
              REFERENCED_COLUMN_NAME
620
            FROM information_schema.KEY_COLUMN_USAGE
621
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
622
              AND REFERENCED_TABLE_NAME IS NOT NULL
623
              AND TABLE_NAME = '%s'
624
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
625
            $tableName
626
        ));
627
        foreach ($rows as $row) {
628
            $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME'];
629
            $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME'];
630
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME'];
631
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
632
        }
633
        return $foreignKeys;
634
    }
635
636
    /**
637
     * {@inheritdoc}

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

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