Code Duplication    Length = 27-28 lines in 3 locations

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

@@ 295-322 (lines=28) @@
292
        }
293
294
        // Set the default primary key and add associated column
295
        if (isset($newOptions['id']) && $newOptions['id'] !== false) {
296
            if ($newOptions['id'] === true) {
297
                $newOptions['primary_key'] = 'id';
298
            } else if (is_string($newOptions['id'])) {
299
                // Handle id => "field_name" to support AUTO_INCREMENT
300
                $newOptions['primary_key'] = $newOptions['id'];
301
            } else {
302
                throw new \InvalidArgumentException(sprintf(
303
                    "Invalid value for option 'id': %s",
304
                    json_encode($newOptions['id'])
305
                ));
306
            }
307
308
            if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) {
309
                throw new \RuntimeException(sprintf(
310
                    "Tried to create primary key column %s for table %s, but that column already exists",
311
                    $this->quoteColumnName($newOptions['primary_key']),
312
                    $this->quoteTableName($table->getName())
313
                ));
314
            }
315
316
            $column = new Column();
317
            $column
318
                ->setName($newOptions['primary_key'])
319
                ->setType('integer')
320
                ->setIdentity(true);
321
            $instructions->merge($this->getAddColumnInstructions($table, $column));
322
        }
323
324
        // Add the primary key(s)
325
        if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) {

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

@@ 267-293 (lines=27) @@
264
        }
265
266
        // Set the default primary key and add associated column
267
        if (isset($newOptions['id']) && $newOptions['id'] !== false) {
268
            if ($newOptions['id'] === true) {
269
                $newOptions['primary_key'] = 'id';
270
            } else if (is_string($newOptions['id'])) {
271
                // Handle id => "field_name" to support AUTO_INCREMENT
272
                $newOptions['primary_key'] = $newOptions['id'];
273
            } else {
274
                throw new \InvalidArgumentException(sprintf(
275
                    "Invalid value for option 'id': %s",
276
                    json_encode($newOptions['id'])
277
                ));
278
            }
279
280
            if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) {
281
                throw new \RuntimeException(sprintf(
282
                    "Tried to create primary key column %s for table %s, but that column already exists",
283
                    $this->quoteColumnName($newOptions['primary_key']),
284
                    $this->quoteTableName($table->getName())
285
                ));
286
            }
287
288
            $column = new Column();
289
            $column
290
                ->setName($newOptions['primary_key'])
291
                ->setType('integer');
292
            $instructions->merge($this->getAddColumnInstructions($table, $column));
293
        }
294
295
        // Add the primary key(s)
296
        if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) {

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

@@ 297-324 (lines=28) @@
294
        }
295
296
        // Set the default primary key and add associated column
297
        if (isset($newOptions['id']) && $newOptions['id'] !== false) {
298
            if ($newOptions['id'] === true) {
299
                $newOptions['primary_key'] = 'id';
300
            } else if (is_string($newOptions['id'])) {
301
                // Handle id => "field_name" to support AUTO_INCREMENT
302
                $newOptions['primary_key'] = $newOptions['id'];
303
            } else {
304
                throw new \InvalidArgumentException(sprintf(
305
                    "Invalid value for option 'id': %s",
306
                    json_encode($newOptions['id'])
307
                ));
308
            }
309
310
            if ($this->hasColumn($table->getName(), $newOptions['primary_key'])) {
311
                throw new \RuntimeException(sprintf(
312
                    "Tried to create primary key column %s for table %s, but that column already exists",
313
                    $this->quoteColumnName($newOptions['primary_key']),
314
                    $this->quoteTableName($table->getName())
315
                ));
316
            }
317
318
            $column = new Column();
319
            $column
320
                ->setName($newOptions['primary_key'])
321
                ->setType('integer')
322
                ->setIdentity(true);
323
            $this->addColumn($table, $column);
324
        }
325
326
        // Add the primary key(s)
327
        if (isset($newOptions['primary_key']) && $newOptions['primary_key'] !== false) {