Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SQLiteAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SQLiteAdapter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class SQLiteAdapter extends PdoAdapter |
||
32 | { |
||
33 | // list of supported Phinx column types with their SQL equivalents |
||
34 | // some types have an affinity appended to ensure they do not receive NUMERIC affinity |
||
35 | protected static $supportedColumnTypes = [ |
||
36 | self::PHINX_TYPE_BIG_INTEGER => 'biginteger', |
||
37 | self::PHINX_TYPE_BINARY => 'binary_blob', |
||
38 | self::PHINX_TYPE_BLOB => 'blob', |
||
39 | self::PHINX_TYPE_BOOLEAN => 'boolean_integer', |
||
40 | self::PHINX_TYPE_CHAR => 'char', |
||
41 | self::PHINX_TYPE_DATE => 'date_text', |
||
42 | self::PHINX_TYPE_DATETIME => 'datetime_text', |
||
43 | self::PHINX_TYPE_DOUBLE => 'double', |
||
44 | self::PHINX_TYPE_FLOAT => 'float', |
||
45 | self::PHINX_TYPE_INTEGER => 'integer', |
||
46 | self::PHINX_TYPE_JSON => 'json_text', |
||
47 | self::PHINX_TYPE_JSONB => 'jsonb_text', |
||
48 | self::PHINX_TYPE_SMALL_INTEGER => 'smallinteger', |
||
49 | self::PHINX_TYPE_STRING => 'varchar', |
||
50 | self::PHINX_TYPE_TEXT => 'text', |
||
51 | self::PHINX_TYPE_TIME => 'time_text', |
||
52 | self::PHINX_TYPE_UUID => 'uuid_text', |
||
53 | self::PHINX_TYPE_TIMESTAMP => 'timestamp_text', |
||
54 | self::PHINX_TYPE_VARBINARY => 'varbinary_blob', |
||
55 | ]; |
||
56 | 42 | ||
57 | // list of aliases of supported column types |
||
58 | 42 | protected static $supportedColumnTypeAliases = [ |
|
59 | 42 | 'varchar' => self::PHINX_TYPE_STRING, |
|
60 | 'tinyint' => self::PHINX_TYPE_SMALL_INTEGER, |
||
61 | 'tinyinteger' => self::PHINX_TYPE_SMALL_INTEGER, |
||
62 | 'smallint' => self::PHINX_TYPE_SMALL_INTEGER, |
||
63 | 'int' => self::PHINX_TYPE_INTEGER, |
||
64 | 'mediumint' => self::PHINX_TYPE_INTEGER, |
||
65 | 42 | 'mediuminteger' => self::PHINX_TYPE_INTEGER, |
|
66 | 42 | 'bigint' => self::PHINX_TYPE_BIG_INTEGER, |
|
67 | 'tinytext' => self::PHINX_TYPE_TEXT, |
||
68 | 'mediumtext' => self::PHINX_TYPE_TEXT, |
||
69 | 42 | 'longtext' => self::PHINX_TYPE_TEXT, |
|
70 | 'tinyblob' => self::PHINX_TYPE_BLOB, |
||
71 | 'mediumblob' => self::PHINX_TYPE_BLOB, |
||
72 | 42 | 'longblob' => self::PHINX_TYPE_BLOB, |
|
73 | 42 | 'real' => self::PHINX_TYPE_FLOAT, |
|
74 | 42 | ]; |
|
75 | 42 | ||
76 | // list of known but unsupported Phinx column types |
||
77 | protected static $unsupportedColumnTypes = [ |
||
78 | self::PHINX_TYPE_BIT, |
||
79 | 42 | self::PHINX_TYPE_CIDR, |
|
80 | 42 | self::PHINX_TYPE_DECIMAL, |
|
81 | self::PHINX_TYPE_ENUM, |
||
82 | self::PHINX_TYPE_FILESTREAM, |
||
83 | self::PHINX_TYPE_GEOMETRY, |
||
84 | self::PHINX_TYPE_INET, |
||
85 | self::PHINX_TYPE_INTERVAL, |
||
86 | self::PHINX_TYPE_LINESTRING, |
||
87 | 42 | self::PHINX_TYPE_MACADDR, |
|
88 | 42 | self::PHINX_TYPE_POINT, |
|
89 | 42 | self::PHINX_TYPE_POLYGON, |
|
90 | self::PHINX_TYPE_SET, |
||
91 | ]; |
||
92 | |||
93 | protected $definitionsWithLimits = [ |
||
94 | 48 | 'CHAR', |
|
95 | 'CHARACTER', |
||
96 | 48 | 'VARCHAR', |
|
97 | 48 | 'VARYING CHARACTER', |
|
98 | 'NCHAR', |
||
99 | 'NATIVE CHARACTER', |
||
100 | 'NVARCHAR', |
||
101 | ]; |
||
102 | |||
103 | protected $suffix = '.sqlite3'; |
||
104 | |||
105 | /** |
||
106 | * Indicates whether the database library version is at least the specified version |
||
107 | * |
||
108 | * @param string $ver The version to check against e.g. '3.28.0' |
||
109 | * |
||
110 | 1 | * @return bool |
|
111 | */ |
||
112 | 1 | public function databaseVersionAtLeast($ver) |
|
113 | 1 | { |
|
114 | $actual = $this->query('SELECT sqlite_version()')->fetchColumn(); |
||
115 | |||
116 | return version_compare($actual, $ver, '>='); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * {@inheritDoc} |
||
121 | * |
||
122 | * @throws \RuntimeException |
||
123 | * @throws \InvalidArgumentException |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | public function connect() |
||
128 | { |
||
129 | if ($this->connection === null) { |
||
130 | if (!class_exists('PDO') || !in_array('sqlite', PDO::getAvailableDrivers(), true)) { |
||
131 | // @codeCoverageIgnoreStart |
||
132 | throw new RuntimeException('You need to enable the PDO_SQLITE extension for Phinx to run properly.'); |
||
133 | // @codeCoverageIgnoreEnd |
||
134 | 43 | } |
|
135 | |||
136 | 43 | $options = $this->getOptions(); |
|
137 | |||
138 | // use a memory database if the option was specified |
||
139 | if (!empty($options['memory'])) { |
||
140 | $dsn = 'sqlite::memory:'; |
||
141 | } else { |
||
142 | 44 | $dsn = 'sqlite:' . $options['name'] . $this->suffix; |
|
143 | } |
||
144 | 44 | ||
145 | $driverOptions = []; |
||
146 | |||
147 | // use custom data fetch mode |
||
148 | View Code Duplication | if (!empty($options['fetch_mode'])) { |
|
|
|||
149 | $driverOptions[PDO::ATTR_DEFAULT_FETCH_MODE] = constant('\PDO::FETCH_' . strtoupper($options['fetch_mode'])); |
||
150 | 42 | } |
|
151 | |||
152 | 42 | $db = $this->createPdoConnection($dsn, null, null, $driverOptions); |
|
153 | 42 | ||
154 | 42 | $this->setConnection($db); |
|
155 | 12 | } |
|
156 | 42 | } |
|
157 | |||
158 | 42 | /** |
|
159 | * @inheritDoc |
||
160 | */ |
||
161 | public function setOptions(array $options) |
||
162 | { |
||
163 | parent::setOptions($options); |
||
164 | 42 | ||
165 | if (isset($options['suffix'])) { |
||
166 | $this->suffix = $options['suffix']; |
||
167 | 42 | } |
|
168 | 42 | //don't "fix" the file extension if it is blank, some people |
|
169 | 42 | //might want a SQLITE db file with absolutely no extension. |
|
170 | 35 | if ($this->suffix !== '' && strpos($this->suffix, '.') !== 0) { |
|
171 | 35 | $this->suffix = '.' . $this->suffix; |
|
172 | 35 | } |
|
173 | 35 | ||
174 | return $this; |
||
175 | 35 | } |
|
176 | 42 | ||
177 | /** |
||
178 | 1 | * {@inheritDoc} |
|
179 | 1 | * |
|
180 | 1 | * @return void |
|
181 | 1 | */ |
|
182 | public function disconnect() |
||
183 | 1 | { |
|
184 | 1 | $this->connection = null; |
|
185 | } |
||
186 | |||
187 | 42 | /** |
|
188 | 42 | * @inheritDoc |
|
189 | 42 | */ |
|
190 | 42 | public function hasTransactions() |
|
191 | 42 | { |
|
192 | return true; |
||
193 | } |
||
194 | 42 | ||
195 | 42 | /** |
|
196 | 42 | * {@inheritDoc} |
|
197 | 42 | * |
|
198 | 42 | * @return void |
|
199 | 42 | */ |
|
200 | public function beginTransaction() |
||
201 | { |
||
202 | 1 | $this->getConnection()->beginTransaction(); |
|
203 | 1 | } |
|
204 | 1 | ||
205 | /** |
||
206 | 1 | * {@inheritDoc} |
|
207 | 1 | * |
|
208 | 1 | * @return void |
|
209 | 1 | */ |
|
210 | 1 | public function commitTransaction() |
|
211 | 1 | { |
|
212 | 42 | $this->getConnection()->commit(); |
|
213 | 42 | } |
|
214 | 37 | ||
215 | /** |
||
216 | * {@inheritDoc} |
||
217 | * |
||
218 | 42 | * @return void |
|
219 | 42 | */ |
|
220 | 1 | public function rollbackTransaction() |
|
221 | 1 | { |
|
222 | 1 | $this->getConnection()->rollBack(); |
|
223 | 1 | } |
|
224 | |||
225 | 42 | /** |
|
226 | * @inheritDoc |
||
227 | 42 | */ |
|
228 | public function quoteTableName($tableName) |
||
229 | 42 | { |
|
230 | 6 | return str_replace('.', '`.`', $this->quoteColumnName($tableName)); |
|
231 | 42 | } |
|
232 | 42 | ||
233 | /** |
||
234 | * @inheritDoc |
||
235 | */ |
||
236 | public function quoteColumnName($columnName) |
||
237 | 1 | { |
|
238 | return '`' . str_replace('`', '``', $columnName) . '`'; |
||
239 | 1 | } |
|
240 | 1 | ||
241 | /** |
||
242 | * @param string $tableName Table name |
||
243 | * @param bool $quoted Whether to return the schema name and table name escaped and quoted. If quoted, the schema (if any) will also be appended with a dot |
||
244 | * |
||
245 | 1 | * @return array |
|
246 | */ |
||
247 | 1 | protected function getSchemaName($tableName, $quoted = false) |
|
248 | 1 | { |
|
249 | if (preg_match("/.\.([^\.]+)$/", $tableName, $match)) { |
||
250 | $table = $match[1]; |
||
251 | $schema = substr($tableName, 0, strlen($tableName) - strlen($match[0]) + 1); |
||
252 | $result = ['schema' => $schema, 'table' => $table]; |
||
253 | 1 | } else { |
|
254 | $result = ['schema' => '', 'table' => $tableName]; |
||
255 | 1 | } |
|
256 | 1 | ||
257 | 1 | if ($quoted) { |
|
258 | 1 | $result['schema'] = $result['schema'] !== '' ? $this->quoteColumnName($result['schema']) . '.' : ''; |
|
259 | $result['table'] = $this->quoteColumnName($result['table']); |
||
260 | 1 | } |
|
261 | 1 | ||
262 | return $result; |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | 1 | * Retrieves information about a given table from one of the SQLite pragmas |
|
267 | * |
||
268 | 1 | * @param string $tableName The table to query |
|
269 | 1 | * @param string $pragma The pragma to query |
|
270 | * |
||
271 | 1 | * @return array |
|
272 | 1 | */ |
|
273 | 1 | protected function getTableInfo($tableName, $pragma = 'table_info') |
|
274 | 1 | { |
|
275 | 1 | $info = $this->getSchemaName($tableName, true); |
|
276 | 1 | ||
277 | return $this->fetchAll(sprintf('PRAGMA %s%s(%s)', $info['schema'], $pragma, $info['table'])); |
||
278 | 1 | } |
|
279 | 1 | ||
280 | 1 | /** |
|
281 | * Searches through all available schemata to find a table and returns an array |
||
282 | 1 | * containing the bare schema name and whether the table exists at all. |
|
283 | 1 | * If no schema was specified and the table does not exist the "main" schema is returned |
|
284 | 1 | * |
|
285 | * @param string $tableName The name of the table to find |
||
286 | 1 | * |
|
287 | 1 | * @return array |
|
288 | */ |
||
289 | 1 | protected function resolveTable($tableName) |
|
334 | 2 | ||
335 | 2 | /** |
|
336 | 2 | * @inheritDoc |
|
337 | */ |
||
338 | 2 | public function hasTable($tableName) |
|
342 | 2 | ||
343 | 2 | /** |
|
344 | 2 | * {@inheritDoc} |
|
345 | 2 | * |
|
346 | 2 | * @return void |
|
347 | */ |
||
348 | 2 | public function createTable(Table $table, array $columns = [], array $indexes = []) |
|
349 | 1 | { |
|
350 | // Add the default primary key |
||
351 | 1 | $options = $table->getOptions(); |
|
410 | |||
411 | 6 | /** |
|
412 | * {@inheritDoc} |
||
413 | 6 | * |
|
414 | 6 | * @throws \InvalidArgumentException |
|
415 | 6 | */ |
|
416 | 6 | protected function getChangePrimaryKeyInstructions(Table $table, $newColumns) |
|
445 | 2 | ||
446 | 2 | /** |
|
447 | 2 | * {@inheritDoc} |
|
448 | 2 | * |
|
449 | 2 | * @throws \BadMethodCallException |
|
450 | * |
||
451 | 2 | * @return void |
|
452 | 2 | */ |
|
453 | 2 | protected function getChangeCommentInstructions(Table $table, $newComment) |
|
457 | 2 | ||
458 | 2 | /** |
|
459 | 2 | * @inheritDoc |
|
460 | */ |
||
461 | 2 | View Code Duplication | protected function getRenameTableInstructions($tableName, $newTableName) |
472 | 2 | ||
473 | 2 | /** |
|
474 | * @inheritDoc |
||
475 | 2 | */ |
|
476 | View Code Duplication | protected function getDropTableInstructions($tableName) |
|
483 | 2 | ||
484 | 2 | /** |
|
485 | 2 | * {@inheritDoc} |
|
486 | 2 | * |
|
487 | 2 | * @return void |
|
488 | */ |
||
489 | 2 | public function truncateTable($tableName) |
|
490 | { |
||
491 | 2 | $info = $this->resolveTable($tableName); |
|
492 | 2 | // first try deleting the rows |
|
493 | 2 | $this->execute(sprintf( |
|
494 | 'DELETE FROM %s.%s', |
||
495 | $this->quoteColumnName($info['schema']), |
||
496 | $this->quoteColumnName($info['table']) |
||
497 | )); |
||
498 | |||
499 | // assuming no error occurred, reset the autoincrement (if any) |
||
500 | if ($this->hasTable($info['schema'] . '.sqlite_sequence')) { |
||
501 | 9 | $this->execute(sprintf( |
|
502 | 'DELETE FROM %s.%s where name = %s', |
||
503 | 9 | $this->quoteColumnName($info['schema']), |
|
504 | 9 | 'sqlite_sequence', |
|
505 | $this->quoteString($info['table']) |
||
506 | 9 | )); |
|
507 | 9 | } |
|
508 | 9 | } |
|
509 | 9 | ||
510 | 9 | /** |
|
511 | 9 | * Parses a default-value expression to yield either a Literal representing |
|
512 | 9 | * a string value, a string representing an expression, or some other scalar |
|
513 | 9 | * |
|
514 | 9 | * @param mixed $v The default-value expression to interpret |
|
515 | 9 | * @param string $t The Phinx type of the column |
|
516 | * |
||
517 | * @return mixed |
||
518 | */ |
||
519 | protected function parseDefaultValue($v, $t) |
||
582 | 1 | ||
583 | 1 | /** |
|
584 | * Returns the name of the specified table's identity column, or null if the table has no identity |
||
585 | 1 | * |
|
586 | 1 | * The process of finding an identity column is somewhat convoluted as SQLite has no direct way of querying whether a given column is an alias for the table's row ID |
|
587 | * |
||
588 | 1 | * @param string $tableName The name of the table |
|
589 | 1 | * |
|
590 | 1 | * @return string|null |
|
591 | 1 | */ |
|
592 | 1 | protected function resolveIdentity($tableName) |
|
626 | |||
627 | 5 | /** |
|
628 | * @inheritDoc |
||
629 | */ |
||
630 | 5 | public function getColumns($tableName) |
|
655 | |||
656 | /** |
||
657 | * @inheritDoc |
||
658 | */ |
||
659 | View Code Duplication | public function hasColumn($tableName, $columnName) |
|
670 | 5 | ||
671 | 5 | /** |
|
672 | 5 | * @inheritDoc |
|
673 | 5 | */ |
|
674 | protected function getAddColumnInstructions(Table $table, Column $column) |
||
701 | |||
702 | 4 | /** |
|
703 | 4 | * Returns the original CREATE statement for the give table |
|
704 | * |
||
705 | 4 | * @param string $tableName The table name to get the create statement for |
|
706 | 4 | * |
|
707 | 4 | * @return string |
|
708 | 4 | */ |
|
709 | 4 | protected function getDeclaringSql($tableName) |
|
722 | |||
723 | 1 | /** |
|
724 | * Copies all the data from a tmp table to another table |
||
725 | * |
||
726 | * @param string $tableName The table name to copy the data to |
||
727 | 1 | * @param string $tmpTableName The tmp table name where the data is stored |
|
728 | * @param string[] $writeColumns The list of columns in the target table |
||
729 | 1 | * @param string[] $selectColumns The list of columns in the tmp table |
|
730 | * |
||
731 | 1 | * @return void |
|
732 | 1 | */ |
|
733 | 1 | protected function copyDataToNewTable($tableName, $tmpTableName, $writeColumns, $selectColumns) |
|
744 | 1 | ||
745 | /** |
||
746 | 1 | * Modifies the passed instructions to copy all data from the table into |
|
747 | * the provided tmp table and then drops the table and rename tmp table. |
||
748 | 1 | * |
|
749 | * @param \Phinx\Db\Util\AlterInstructions $instructions The instructions to modify |
||
750 | * @param string $tableName The table name to copy the data to |
||
751 | * |
||
752 | * @return \Phinx\Db\Util\AlterInstructions |
||
753 | */ |
||
754 | 1 | protected function copyAndDropTmpTable($instructions, $tableName) |
|
776 | 1 | ||
777 | /** |
||
778 | * Returns the columns and type to use when copying a table to another in the process |
||
779 | * of altering a table |
||
780 | * |
||
781 | * @param string $tableName The table to modify |
||
782 | * @param string|false $columnName The column name that is about to change |
||
783 | * @param string|false $newColumnName Optionally the new name for the column |
||
784 | * |
||
785 | * @throws \InvalidArgumentException |
||
786 | * |
||
787 | * @return \Phinx\Db\Util\AlterInstructions |
||
788 | */ |
||
789 | protected function calculateNewTableColumns($tableName, $columnName, $newColumnName) |
||
825 | 43 | ||
826 | 42 | /** |
|
827 | * Returns the initial instructions to alter a table using the |
||
828 | 43 | * create-copy-drop strategy |
|
829 | 2 | * |
|
830 | * @param string $tableName The table to modify |
||
831 | 43 | * |
|
832 | 1 | * @return \Phinx\Db\Util\AlterInstructions |
|
833 | */ |
||
834 | 43 | protected function beginAlterByCopyTable($tableName) |
|
861 | 1 | ||
862 | /** |
||
863 | * @inheritDoc |
||
864 | 1 | */ |
|
865 | protected function getRenameColumnInstructions($tableName, $columnName, $newColumnName) |
||
888 | 2 | ||
889 | 1 | /** |
|
890 | 1 | * @inheritDoc |
|
891 | 2 | */ |
|
892 | protected function getChangeColumnInstructions($tableName, $columnName, Column $newColumn) |
||
917 | 1 | ||
918 | /** |
||
919 | * @inheritDoc |
||
920 | 1 | */ |
|
921 | 1 | protected function getDropColumnInstructions($tableName, $columnName) |
|
949 | 48 | ||
950 | /** |
||
951 | * Get an array of indexes from a particular table. |
||
952 | * |
||
953 | * @param string $tableName Table Name |
||
954 | 2 | * |
|
955 | * @return array |
||
956 | 2 | */ |
|
957 | protected function getIndexes($tableName) |
||
974 | |||
975 | 42 | /** |
|
976 | * Finds the names of a table's indexes matching the supplied columns |
||
977 | 42 | * |
|
978 | 8 | * @param string $tableName The table to which the index belongs |
|
979 | 42 | * @param string|string[] $columns The columns of the index |
|
980 | 42 | * |
|
981 | 42 | * @return array |
|
982 | 42 | */ |
|
983 | protected function resolveIndex($tableName, $columns) |
||
998 | |||
999 | 42 | /** |
|
1000 | 42 | * @inheritDoc |
|
1001 | 42 | */ |
|
1002 | 42 | public function hasIndex($tableName, $columns) |
|
1006 | |||
1007 | 42 | /** |
|
1008 | * @inheritDoc |
||
1009 | 42 | */ |
|
1010 | 42 | public function hasIndexByName($tableName, $indexName) |
|
1023 | |||
1024 | /** |
||
1025 | * @inheritDoc |
||
1026 | */ |
||
1027 | protected function getAddIndexInstructions(Table $table, Index $index) |
||
1043 | |||
1044 | 8 | /** |
|
1045 | 2 | * @inheritDoc |
|
1046 | 2 | */ |
|
1047 | 6 | protected function getDropIndexByColumnsInstructions($tableName, $columns) |
|
1064 | |||
1065 | 47 | /** |
|
1066 | * @inheritDoc |
||
1067 | 47 | */ |
|
1068 | protected function getDropIndexByNameInstructions($tableName, $indexName) |
||
1093 | 1 | ||
1094 | 1 | /** |
|
1095 | 5 | * {@inheritDoc} |
|
1096 | 1 | * |
|
1097 | 1 | * @throws \InvalidArgumentException |
|
1098 | */ |
||
1099 | 5 | public function hasPrimaryKey($tableName, $columns, $constraint = null) |
|
1114 | |||
1115 | /** |
||
1116 | * Get the primary key from a particular table. |
||
1117 | * |
||
1118 | * @param string $tableName Table Name |
||
1119 | * |
||
1120 | * @return string[] |
||
1121 | */ |
||
1122 | protected function getPrimaryKey($tableName) |
||
1136 | |||
1137 | /** |
||
1138 | * {@inheritDoc} |
||
1139 | * |
||
1140 | * @throws \InvalidArgumentException |
||
1141 | */ |
||
1142 | public function hasForeignKey($tableName, $columns, $constraint = null) |
||
1162 | |||
1163 | /** |
||
1164 | * Get an array of foreign keys from a particular table. |
||
1165 | * |
||
1166 | * @param string $tableName Table Name |
||
1167 | * |
||
1168 | * @return array |
||
1169 | */ |
||
1170 | protected function getForeignKeys($tableName) |
||
1185 | |||
1186 | /** |
||
1187 | * @param \Phinx\Db\Table\Table $table The Table |
||
1188 | * @param string $column Column Name |
||
1189 | * |
||
1190 | * @return \Phinx\Db\Util\AlterInstructions |
||
1191 | */ |
||
1192 | protected function getAddPrimaryKeyInstructions(Table $table, $column) |
||
1229 | |||
1230 | /** |
||
1231 | * @param \Phinx\Db\Table\Table $table Table |
||
1232 | * @param string $column Column Name |
||
1233 | * |
||
1234 | * @return \Phinx\Db\Util\AlterInstructions |
||
1235 | */ |
||
1236 | protected function getDropPrimaryKeyInstructions($table, $column) |
||
1259 | |||
1260 | /** |
||
1261 | * @inheritDoc |
||
1262 | */ |
||
1263 | protected function getAddForeignKeyInstructions(Table $table, ForeignKey $foreignKey) |
||
1286 | |||
1287 | /** |
||
1288 | * {@inheritDoc} |
||
1289 | * |
||
1290 | * @throws \BadMethodCallException |
||
1291 | * |
||
1292 | * @return void |
||
1293 | */ |
||
1294 | protected function getDropForeignKeyInstructions($tableName, $constraint) |
||
1298 | |||
1299 | /** |
||
1300 | * {@inheritDoc} |
||
1301 | * |
||
1302 | * @throws \InvalidArgumentException |
||
1303 | */ |
||
1304 | protected function getDropForeignKeyByColumnsInstructions($tableName, $columns) |
||
1344 | |||
1345 | /** |
||
1346 | * {@inheritDoc} |
||
1347 | * |
||
1348 | * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException |
||
1349 | */ |
||
1350 | public function getSqlType($type, $limit = null) |
||
1365 | |||
1366 | /** |
||
1367 | * Returns Phinx type by SQL type |
||
1368 | * |
||
1369 | * @param string|null $sqlTypeDef SQL type |
||
1370 | * |
||
1371 | * @return array |
||
1372 | */ |
||
1373 | public function getPhinxType($sqlTypeDef) |
||
1415 | |||
1416 | /** |
||
1417 | * {@inheritDoc} |
||
1418 | * |
||
1419 | * @return void |
||
1420 | */ |
||
1421 | public function createDatabase($name, $options = []) |
||
1425 | |||
1426 | /** |
||
1427 | * @inheritDoc |
||
1428 | */ |
||
1429 | public function hasDatabase($name) |
||
1433 | |||
1434 | /** |
||
1435 | * {@inheritDoc} |
||
1436 | * |
||
1437 | * @return void |
||
1438 | */ |
||
1439 | public function dropDatabase($name) |
||
1449 | |||
1450 | /** |
||
1451 | * Gets the SQLite Column Definition for a Column object. |
||
1452 | * |
||
1453 | * @param \Phinx\Db\Table\Column $column Column |
||
1454 | * |
||
1455 | * @return string |
||
1456 | */ |
||
1457 | protected function getColumnSqlDefinition(Column $column) |
||
1489 | |||
1490 | /** |
||
1491 | * Gets the comment Definition for a Column object. |
||
1492 | * |
||
1493 | * @param \Phinx\Db\Table\Column $column Column |
||
1494 | * |
||
1495 | * @return string |
||
1496 | */ |
||
1497 | protected function getCommentDefinition(Column $column) |
||
1505 | |||
1506 | /** |
||
1507 | * Gets the SQLite Index Definition for an Index object. |
||
1508 | * |
||
1509 | * @param \Phinx\Db\Table\Table $table Table |
||
1510 | * @param \Phinx\Db\Table\Index $index Index |
||
1511 | * |
||
1512 | * @return string |
||
1513 | */ |
||
1514 | protected function getIndexSqlDefinition(Table $table, Index $index) |
||
1534 | |||
1535 | /** |
||
1536 | * @inheritDoc |
||
1537 | */ |
||
1538 | public function getColumnTypes() |
||
1539 | { |
||
1540 | return array_keys(self::$supportedColumnTypes); |
||
1541 | } |
||
1542 | |||
1543 | /** |
||
1544 | * Gets the SQLite Foreign Key Definition for an ForeignKey object. |
||
1545 | * |
||
1546 | * @param \Phinx\Db\Table\ForeignKey $foreignKey |
||
1547 | * |
||
1548 | * @return string |
||
1549 | */ |
||
1550 | View Code Duplication | protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) |
|
1576 | |||
1577 | /** |
||
1578 | * @inheritDoc |
||
1579 | */ |
||
1580 | public function getDecoratedConnection() |
||
1599 | } |
||
1600 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.