Code Duplication    Length = 25-26 lines in 3 locations

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}

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

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

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

@@ 657-681 (lines=25) @@
654
     * @param string $tableName Table Name
655
     * @return array
656
     */
657
    protected function getForeignKeys($tableName)
658
    {
659
        $foreignKeys = [];
660
        $rows = $this->fetchAll(sprintf(
661
            "SELECT
662
                    tc.constraint_name,
663
                    tc.table_name, kcu.column_name,
664
                    ccu.table_name AS referenced_table_name,
665
                    ccu.column_name AS referenced_column_name
666
                FROM
667
                    information_schema.table_constraints AS tc
668
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
669
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
670
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
671
                ORDER BY kcu.position_in_unique_constraint",
672
            $tableName
673
        ));
674
        foreach ($rows as $row) {
675
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
676
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
677
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
678
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
679
        }
680
681
        return $foreignKeys;
682
    }
683
684
    /**