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/PostgresAdapter.php 1 location

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

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

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