Code Duplication    Length = 22-22 lines in 3 locations

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

@@ 260-281 (lines=22) @@
257
        }
258
259
        // set the primary key(s)
260
        if (isset($options['primary_key'])) {
261
            $sql = rtrim($sql);
262
            $sql .= ' PRIMARY KEY (';
263
            if (is_string($options['primary_key'])) {       // handle primary_key => 'id'
264
                $sql .= $this->quoteColumnName($options['primary_key']);
265
            } elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id')
266
                // PHP 5.4 will allow access of $this, so we can call quoteColumnName() directly in the
267
                // anonymous function, but for now just hard-code the adapter quotes
268
                $sql .= implode(
269
                    ',',
270
                    array_map(
271
                        function ($v) {
272
                            return '`' . $v . '`';
273
                        },
274
                        $options['primary_key']
275
                    )
276
                );
277
            }
278
            $sql .= ')';
279
        } else {
280
            $sql = substr(rtrim($sql), 0, -1);              // no primary keys
281
        }
282
283
        // set the indexes
284
        $indexes = $table->getIndexes();

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

@@ 194-215 (lines=22) @@
191
        }
192
193
        // set the primary key(s)
194
        if (isset($options['primary_key'])) {
195
            $sql = rtrim($sql);
196
            $sql .= ' PRIMARY KEY (';
197
            if (is_string($options['primary_key'])) {       // handle primary_key => 'id'
198
                $sql .= $this->quoteColumnName($options['primary_key']);
199
            } elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id')
200
                // PHP 5.4 will allow access of $this, so we can call quoteColumnName() directly in the anonymous function,
201
                // but for now just hard-code the adapter quotes
202
                $sql .= implode(
203
                    ',',
204
                    array_map(
205
                        function ($v) {
206
                            return '`' . $v . '`';
207
                        },
208
                        $options['primary_key']
209
                    )
210
                );
211
            }
212
            $sql .= ')';
213
        } else {
214
            $sql = substr(rtrim($sql), 0, -1);              // no primary keys
215
        }
216
217
        // set the foreign keys
218
        $foreignKeys = $table->getForeignKeys();

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

@@ 212-233 (lines=22) @@
209
        }
210
211
         // set the primary key(s)
212
        if (isset($options['primary_key'])) {
213
            $sql = rtrim($sql);
214
            $sql .= sprintf(' CONSTRAINT %s_pkey PRIMARY KEY (', $table->getName());
215
            if (is_string($options['primary_key'])) {       // handle primary_key => 'id'
216
                $sql .= $this->quoteColumnName($options['primary_key']);
217
            } elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id')
218
                // PHP 5.4 will allow access of $this, so we can call quoteColumnName() directly in the anonymous function,
219
                // but for now just hard-code the adapter quotes
220
                $sql .= implode(
221
                    ',',
222
                    array_map(
223
                        function ($v) {
224
                            return '"' . $v . '"';
225
                        },
226
                        $options['primary_key']
227
                    )
228
                );
229
            }
230
            $sql .= ')';
231
        } else {
232
            $sql = rtrim($sql, ', '); // no primary keys
233
        }
234
235
        // set the foreign keys
236
        $foreignKeys = $table->getForeignKeys();