Code Duplication    Length = 18-22 lines in 2 locations

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

@@ 826-843 (lines=18) @@
823
    {
824
        $instructions = new AlterInstructions();
825
826
        foreach ($columns as $column) {
827
            $rows = $this->fetchAll(sprintf(
828
                "SELECT
829
                    CONSTRAINT_NAME
830
                  FROM information_schema.KEY_COLUMN_USAGE
831
                  WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
832
                    AND REFERENCED_TABLE_NAME IS NOT NULL
833
                    AND TABLE_NAME = '%s'
834
                    AND COLUMN_NAME = '%s'
835
                  ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
836
                $tableName,
837
                $column
838
            ));
839
840
            foreach ($rows as $row) {
841
                $instructions->merge($this->getDropForeignKeyInstructions($tableName, $row['CONSTRAINT_NAME']));
842
            }
843
        }
844
845
        if (empty($instructions->getAlterParts())) {
846
            throw new \InvalidArgumentException(sprintf(

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

@@ 983-1004 (lines=22) @@
980
    {
981
        $instructions = new AlterInstructions();
982
983
        foreach ($columns as $column) {
984
            $rows = $this->fetchAll(sprintf(
985
                "SELECT
986
                tc.constraint_name,
987
                tc.table_name, kcu.column_name,
988
                ccu.table_name AS referenced_table_name,
989
                ccu.column_name AS referenced_column_name
990
            FROM
991
                information_schema.table_constraints AS tc
992
                JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
993
                JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
994
            WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' and ccu.column_name='%s'
995
            ORDER BY kcu.ordinal_position",
996
                $tableName,
997
                $column
998
            ));
999
            foreach ($rows as $row) {
1000
                $instructions->merge(
1001
                    $this->getDropForeignKeyInstructions($tableName, $row['constraint_name'])
1002
                );
1003
            }
1004
        }
1005
1006
        return $instructions;
1007
    }