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