Code Duplication    Length = 25-26 lines in 3 locations

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

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

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

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

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

@@ 669-693 (lines=25) @@
666
     * @param string $tableName Table Name
667
     * @return array
668
     */
669
    protected function getForeignKeys($tableName)
670
    {
671
        $foreignKeys = [];
672
        $rows = $this->fetchAll(sprintf(
673
            "SELECT
674
                    tc.constraint_name,
675
                    tc.table_name, kcu.column_name,
676
                    ccu.table_name AS referenced_table_name,
677
                    ccu.column_name AS referenced_column_name
678
                FROM
679
                    information_schema.table_constraints AS tc
680
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
681
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
682
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
683
                ORDER BY kcu.position_in_unique_constraint",
684
            $tableName
685
        ));
686
        foreach ($rows as $row) {
687
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
688
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
689
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
690
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
691
        }
692
693
        return $foreignKeys;
694
    }
695
696
    /**