Code Duplication    Length = 25-26 lines in 3 locations

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
    /**

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}