Code Duplication    Length = 18-22 lines in 2 locations

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

@@ 806-823 (lines=18) @@
803
    {
804
        $instructions = new AlterInstructions();
805
806
        foreach ($columns as $column) {
807
            $rows = $this->fetchAll(sprintf(
808
                "SELECT
809
                    CONSTRAINT_NAME
810
                  FROM information_schema.KEY_COLUMN_USAGE
811
                  WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
812
                    AND REFERENCED_TABLE_NAME IS NOT NULL
813
                    AND TABLE_NAME = '%s'
814
                    AND COLUMN_NAME = '%s'
815
                  ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
816
                $tableName,
817
                $column
818
            ));
819
820
            foreach ($rows as $row) {
821
                $instructions->merge($this->getDropForeignKeyInstructions($tableName, $row['CONSTRAINT_NAME']));
822
            }
823
        }
824
825
        if (empty($instructions->getAlterParts())) {
826
            throw new \InvalidArgumentException(sprintf(

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

@@ 971-992 (lines=22) @@
968
    {
969
        $instructions = new AlterInstructions();
970
971
        foreach ($columns as $column) {
972
            $rows = $this->fetchAll(sprintf(
973
                "SELECT
974
                tc.constraint_name,
975
                tc.table_name, kcu.column_name,
976
                ccu.table_name AS referenced_table_name,
977
                ccu.column_name AS referenced_column_name
978
            FROM
979
                information_schema.table_constraints AS tc
980
                JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
981
                JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
982
            WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' and ccu.column_name='%s'
983
            ORDER BY kcu.ordinal_position",
984
                $tableName,
985
                $column
986
            ));
987
            foreach ($rows as $row) {
988
                $instructions->merge(
989
                    $this->getDropForeignKeyInstructions($tableName, $row['constraint_name'])
990
                );
991
            }
992
        }
993
994
        return $instructions;
995
    }