Code Duplication    Length = 25-26 lines in 3 locations

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

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

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

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

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

@@ 593-617 (lines=25) @@
590
	 *
591
	 * @return array
592
	 */
593
	protected function getForeignKeys( $tableName ) {
594
		$foreignKeys = [];
595
		$rows        = $this->fetchAll( sprintf(
596
			"SELECT
597
              CONSTRAINT_NAME,
598
              TABLE_NAME,
599
              COLUMN_NAME,
600
              REFERENCED_TABLE_NAME,
601
              REFERENCED_COLUMN_NAME
602
            FROM information_schema.KEY_COLUMN_USAGE
603
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
604
              AND REFERENCED_TABLE_NAME IS NOT NULL
605
              AND TABLE_NAME = '%s'
606
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
607
			$tableName
608
		) );
609
		foreach ( $rows as $row ) {
610
			$foreignKeys[ $row['CONSTRAINT_NAME'] ]['table']                = $row['TABLE_NAME'];
611
			$foreignKeys[ $row['CONSTRAINT_NAME'] ]['columns'][]            = $row['COLUMN_NAME'];
612
			$foreignKeys[ $row['CONSTRAINT_NAME'] ]['referenced_table']     = $row['REFERENCED_TABLE_NAME'];
613
			$foreignKeys[ $row['CONSTRAINT_NAME'] ]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
614
		}
615
616
		return $foreignKeys;
617
	}
618
619
	/**
620
	 * {@inheritdoc}