Code Duplication    Length = 25-26 lines in 2 locations

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

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

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

@@ 793-818 (lines=26) @@
790
     * @param string $tableName Table Name
791
     * @return array
792
     */
793
    protected function getForeignKeys($tableName)
794
    {
795
        $foreignKeys = [];
796
        $rows = $this->fetchAll(sprintf(
797
            "SELECT
798
                    tc.constraint_name,
799
                    tc.table_name, kcu.column_name,
800
                    ccu.table_name AS referenced_table_name,
801
                    ccu.column_name AS referenced_column_name
802
                FROM
803
                    information_schema.table_constraints AS tc
804
                    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
805
                    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
806
                WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s'
807
                ORDER BY kcu.ordinal_position",
808
            $tableName
809
        ));
810
        foreach ($rows as $row) {
811
            $foreignKeys[$row['constraint_name']]['table'] = $row['table_name'];
812
            $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name'];
813
            $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name'];
814
            $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name'];
815
        }
816
817
        return $foreignKeys;
818
    }
819
820
    /**
821
     * {@inheritdoc}