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 SQLAnywherePlatform 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 SQLAnywherePlatform, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
56 | class SQLAnywherePlatform extends AbstractPlatform |
||
57 | { |
||
58 | /** |
||
59 | * @var int |
||
60 | */ |
||
61 | const FOREIGN_KEY_MATCH_SIMPLE = 1; |
||
62 | /** |
||
63 | * @var int |
||
64 | */ |
||
65 | const FOREIGN_KEY_MATCH_FULL = 2; |
||
66 | /** |
||
67 | * @var int |
||
68 | */ |
||
69 | const FOREIGN_KEY_MATCH_SIMPLE_UNIQUE = 129; |
||
70 | /** |
||
71 | * @var int |
||
72 | */ |
||
73 | const FOREIGN_KEY_MATCH_FULL_UNIQUE = 130; |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public function appendLockHint($fromClause, $lockMode) |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | * |
||
98 | * SQL Anywhere supports a maximum length of 128 bytes for identifiers. |
||
99 | */ |
||
100 | public function fixSchemaElementName($schemaElementName) |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | public function getAlterTableSQL(TableDiff $diff) |
||
231 | |||
232 | /** |
||
233 | * Returns the SQL clause for creating a column in a table alteration. |
||
234 | * |
||
235 | * @param Column $column The column to add. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | protected function getAlterTableAddColumnClause(Column $column) |
||
243 | |||
244 | /** |
||
245 | * Returns the SQL clause for altering a table. |
||
246 | * |
||
247 | * @param Identifier $tableName The quoted name of the table to alter. |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | protected function getAlterTableClause(Identifier $tableName) |
||
255 | |||
256 | /** |
||
257 | * Returns the SQL clause for dropping a column in a table alteration. |
||
258 | * |
||
259 | * @param Column $column The column to drop. |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | protected function getAlterTableRemoveColumnClause(Column $column) |
||
267 | |||
268 | /** |
||
269 | * Returns the SQL clause for renaming a column in a table alteration. |
||
270 | * |
||
271 | * @param string $oldColumnName The quoted name of the column to rename. |
||
272 | * @param Column $column The column to rename to. |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | protected function getAlterTableRenameColumnClause($oldColumnName, Column $column) |
||
282 | |||
283 | /** |
||
284 | * Returns the SQL clause for renaming a table in a table alteration. |
||
285 | * |
||
286 | * @param Identifier $newTableName The quoted name of the table to rename to. |
||
287 | * |
||
288 | * @return string |
||
289 | */ |
||
290 | protected function getAlterTableRenameTableClause(Identifier $newTableName) |
||
294 | |||
295 | /** |
||
296 | * Returns the SQL clause for altering a column in a table alteration. |
||
297 | * |
||
298 | * This method returns null in case that only the column comment has changed. |
||
299 | * Changes in column comments have to be handled differently. |
||
300 | * |
||
301 | * @param ColumnDiff $columnDiff The diff of the column to alter. |
||
302 | * |
||
303 | * @return string|null |
||
304 | */ |
||
305 | protected function getAlterTableChangeColumnClause(ColumnDiff $columnDiff) |
||
323 | |||
324 | /** |
||
325 | * {@inheritdoc} |
||
326 | */ |
||
327 | public function getBigIntTypeDeclarationSQL(array $columnDef) |
||
333 | |||
334 | /** |
||
335 | * {@inheritdoc} |
||
336 | */ |
||
337 | public function getBinaryDefaultLength() |
||
341 | |||
342 | /** |
||
343 | * {@inheritdoc} |
||
344 | */ |
||
345 | public function getBinaryMaxLength() |
||
349 | |||
350 | /** |
||
351 | * {@inheritdoc} |
||
352 | */ |
||
353 | public function getBlobTypeDeclarationSQL(array $field) |
||
357 | |||
358 | /** |
||
359 | * {@inheritdoc} |
||
360 | * |
||
361 | * BIT type columns require an explicit NULL declaration |
||
362 | * in SQL Anywhere if they shall be nullable. |
||
363 | * Otherwise by just omitting the NOT NULL clause, |
||
364 | * SQL Anywhere will declare them NOT NULL nonetheless. |
||
365 | */ |
||
366 | public function getBooleanTypeDeclarationSQL(array $columnDef) |
||
372 | |||
373 | /** |
||
374 | * {@inheritdoc} |
||
375 | */ |
||
376 | public function getClobTypeDeclarationSQL(array $field) |
||
380 | |||
381 | /** |
||
382 | * {@inheritdoc} |
||
383 | */ |
||
384 | View Code Duplication | public function getCommentOnColumnSQL($tableName, $columnName, $comment) |
|
393 | |||
394 | /** |
||
395 | * {@inheritdoc} |
||
396 | */ |
||
397 | public function getConcatExpression() |
||
401 | |||
402 | /** |
||
403 | * {@inheritdoc} |
||
404 | */ |
||
405 | public function getCreateConstraintSQL(Constraint $constraint, $table) |
||
418 | |||
419 | /** |
||
420 | * {@inheritdoc} |
||
421 | */ |
||
422 | public function getCreateDatabaseSQL($database) |
||
428 | |||
429 | /** |
||
430 | * {@inheritdoc} |
||
431 | * |
||
432 | * Appends SQL Anywhere specific flags if given. |
||
433 | */ |
||
434 | public function getCreateIndexSQL(Index $index, $table) |
||
438 | |||
439 | /** |
||
440 | * {@inheritdoc} |
||
441 | */ |
||
442 | public function getCreatePrimaryKeySQL(Index $index, $table) |
||
450 | |||
451 | /** |
||
452 | * {@inheritdoc} |
||
453 | */ |
||
454 | public function getCreateTemporaryTableSnippetSQL() |
||
458 | |||
459 | /** |
||
460 | * {@inheritdoc} |
||
461 | */ |
||
462 | public function getCreateViewSQL($name, $sql) |
||
466 | |||
467 | /** |
||
468 | * {@inheritdoc} |
||
469 | */ |
||
470 | public function getCurrentDateSQL() |
||
474 | |||
475 | /** |
||
476 | * {@inheritdoc} |
||
477 | */ |
||
478 | public function getCurrentTimeSQL() |
||
482 | |||
483 | /** |
||
484 | * {@inheritdoc} |
||
485 | */ |
||
486 | public function getCurrentTimestampSQL() |
||
490 | |||
491 | /** |
||
492 | * {@inheritdoc} |
||
493 | */ |
||
494 | protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) |
||
504 | |||
505 | /** |
||
506 | * {@inheritdoc} |
||
507 | */ |
||
508 | public function getDateDiffExpression($date1, $date2) |
||
512 | |||
513 | /** |
||
514 | * {@inheritdoc} |
||
515 | */ |
||
516 | public function getDateTimeFormatString() |
||
520 | |||
521 | /** |
||
522 | * {@inheritdoc} |
||
523 | */ |
||
524 | public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) |
||
528 | |||
529 | /** |
||
530 | * {@inheritdoc} |
||
531 | */ |
||
532 | public function getDateTimeTzFormatString() |
||
536 | |||
537 | /** |
||
538 | * {@inheritdoc} |
||
539 | */ |
||
540 | public function getDateTypeDeclarationSQL(array $fieldDeclaration) |
||
544 | |||
545 | /** |
||
546 | * {@inheritdoc} |
||
547 | */ |
||
548 | public function getDefaultTransactionIsolationLevel() |
||
552 | |||
553 | /** |
||
554 | * {@inheritdoc} |
||
555 | */ |
||
556 | public function getDropDatabaseSQL($database) |
||
562 | |||
563 | /** |
||
564 | * {@inheritdoc} |
||
565 | */ |
||
566 | public function getDropIndexSQL($index, $table = null) |
||
596 | |||
597 | /** |
||
598 | * {@inheritdoc} |
||
599 | */ |
||
600 | public function getDropViewSQL($name) |
||
604 | |||
605 | /** |
||
606 | * {@inheritdoc} |
||
607 | */ |
||
608 | public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) |
||
641 | |||
642 | /** |
||
643 | * Returns foreign key MATCH clause for given type. |
||
644 | * |
||
645 | * @param int $type The foreign key match type |
||
646 | * |
||
647 | * @return string |
||
648 | * |
||
649 | * @throws \InvalidArgumentException if unknown match type given |
||
650 | */ |
||
651 | public function getForeignKeyMatchClauseSQL($type) |
||
669 | |||
670 | /** |
||
671 | * {@inheritdoc} |
||
672 | */ |
||
673 | public function getForeignKeyReferentialActionSQL($action) |
||
682 | |||
683 | /** |
||
684 | * {@inheritdoc} |
||
685 | */ |
||
686 | public function getForUpdateSQL() |
||
690 | |||
691 | /** |
||
692 | * {@inheritdoc} |
||
693 | * |
||
694 | * @deprecated Use application-generated UUIDs instead |
||
695 | */ |
||
696 | public function getGuidExpression() |
||
700 | |||
701 | /** |
||
702 | * {@inheritdoc} |
||
703 | */ |
||
704 | public function getGuidTypeDeclarationSQL(array $field) |
||
708 | |||
709 | /** |
||
710 | * {@inheritdoc} |
||
711 | */ |
||
712 | public function getIndexDeclarationSQL($name, Index $index) |
||
717 | |||
718 | /** |
||
719 | * {@inheritdoc} |
||
720 | */ |
||
721 | public function getIntegerTypeDeclarationSQL(array $columnDef) |
||
727 | |||
728 | /** |
||
729 | * {@inheritdoc} |
||
730 | */ |
||
731 | public function getListDatabasesSQL() |
||
735 | |||
736 | /** |
||
737 | * {@inheritdoc} |
||
738 | */ |
||
739 | public function getListTableColumnsSQL($table, $database = null) |
||
765 | |||
766 | /** |
||
767 | * {@inheritdoc} |
||
768 | * |
||
769 | * @todo Where is this used? Which information should be retrieved? |
||
770 | */ |
||
771 | View Code Duplication | public function getListTableConstraintsSQL($table) |
|
789 | |||
790 | /** |
||
791 | * {@inheritdoc} |
||
792 | */ |
||
793 | View Code Duplication | public function getListTableForeignKeysSQL($table) |
|
875 | |||
876 | /** |
||
877 | * {@inheritdoc} |
||
878 | */ |
||
879 | View Code Duplication | public function getListTableIndexesSQL($table, $currentDatabase = null) |
|
928 | |||
929 | /** |
||
930 | * {@inheritdoc} |
||
931 | */ |
||
932 | public function getListTablesSQL() |
||
943 | |||
944 | /** |
||
945 | * {@inheritdoc} |
||
946 | * |
||
947 | * @todo Where is this used? Which information should be retrieved? |
||
948 | */ |
||
949 | public function getListUsersSQL() |
||
953 | |||
954 | /** |
||
955 | * {@inheritdoc} |
||
956 | */ |
||
957 | public function getListViewsSQL($database) |
||
967 | |||
968 | /** |
||
969 | * {@inheritdoc} |
||
970 | */ |
||
971 | View Code Duplication | public function getLocateExpression($str, $substr, $startPos = false) |
|
979 | |||
980 | /** |
||
981 | * {@inheritdoc} |
||
982 | */ |
||
983 | public function getMaxIdentifierLength() |
||
987 | |||
988 | /** |
||
989 | * {@inheritdoc} |
||
990 | */ |
||
991 | public function getMd5Expression($column) |
||
995 | |||
996 | /** |
||
997 | * {@inheritdoc} |
||
998 | */ |
||
999 | public function getName() |
||
1003 | |||
1004 | /** |
||
1005 | * Obtain DBMS specific SQL code portion needed to set a primary key |
||
1006 | * declaration to be used in statements like ALTER TABLE. |
||
1007 | * |
||
1008 | * @param Index $index Index definition |
||
1009 | * @param string $name Name of the primary key |
||
1010 | * |
||
1011 | * @return string DBMS specific SQL code portion needed to set a primary key |
||
1012 | * |
||
1013 | * @throws \InvalidArgumentException if the given index is not a primary key. |
||
1014 | */ |
||
1015 | public function getPrimaryKeyDeclarationSQL(Index $index, $name = null) |
||
1025 | |||
1026 | /** |
||
1027 | * {@inheritdoc} |
||
1028 | */ |
||
1029 | public function getSetTransactionIsolationSQL($level) |
||
1033 | |||
1034 | /** |
||
1035 | * {@inheritdoc} |
||
1036 | */ |
||
1037 | public function getSmallIntTypeDeclarationSQL(array $columnDef) |
||
1043 | |||
1044 | /** |
||
1045 | * Returns the SQL statement for starting an existing database. |
||
1046 | * |
||
1047 | * In SQL Anywhere you can start and stop databases on a |
||
1048 | * database server instance. |
||
1049 | * This is a required statement after having created a new database |
||
1050 | * as it has to be explicitly started to be usable. |
||
1051 | * SQL Anywhere does not automatically start a database after creation! |
||
1052 | * |
||
1053 | * @param string $database Name of the database to start. |
||
1054 | * |
||
1055 | * @return string |
||
1056 | */ |
||
1057 | public function getStartDatabaseSQL($database) |
||
1063 | |||
1064 | /** |
||
1065 | * Returns the SQL statement for stopping a running database. |
||
1066 | * |
||
1067 | * In SQL Anywhere you can start and stop databases on a |
||
1068 | * database server instance. |
||
1069 | * This is a required statement before dropping an existing database |
||
1070 | * as it has to be explicitly stopped before it can be dropped. |
||
1071 | * |
||
1072 | * @param string $database Name of the database to stop. |
||
1073 | * |
||
1074 | * @return string |
||
1075 | */ |
||
1076 | public function getStopDatabaseSQL($database) |
||
1082 | |||
1083 | /** |
||
1084 | * {@inheritdoc} |
||
1085 | */ |
||
1086 | View Code Duplication | public function getSubstringExpression($value, $from, $length = null) |
|
1094 | |||
1095 | /** |
||
1096 | * {@inheritdoc} |
||
1097 | */ |
||
1098 | public function getTemporaryTableSQL() |
||
1102 | |||
1103 | /** |
||
1104 | * {@inheritdoc} |
||
1105 | */ |
||
1106 | public function getTimeFormatString() |
||
1110 | |||
1111 | /** |
||
1112 | * {@inheritdoc} |
||
1113 | */ |
||
1114 | public function getTimeTypeDeclarationSQL(array $fieldDeclaration) |
||
1118 | |||
1119 | /** |
||
1120 | * {@inheritdoc} |
||
1121 | */ |
||
1122 | public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) |
||
1148 | |||
1149 | /** |
||
1150 | * {@inheritdoc} |
||
1151 | */ |
||
1152 | public function getTruncateTableSQL($tableName, $cascade = false) |
||
1158 | |||
1159 | /** |
||
1160 | * {@inheritdoc} |
||
1161 | */ |
||
1162 | public function getUniqueConstraintDeclarationSQL($name, Index $index) |
||
1179 | |||
1180 | /** |
||
1181 | * {@inheritdoc} |
||
1182 | */ |
||
1183 | public function getVarcharDefaultLength() |
||
1187 | |||
1188 | /** |
||
1189 | * {@inheritdoc} |
||
1190 | */ |
||
1191 | public function getVarcharMaxLength() |
||
1195 | |||
1196 | /** |
||
1197 | * {@inheritdoc} |
||
1198 | */ |
||
1199 | public function hasNativeGuidType() |
||
1203 | |||
1204 | /** |
||
1205 | * {@inheritdoc} |
||
1206 | */ |
||
1207 | public function prefersIdentityColumns() |
||
1211 | |||
1212 | /** |
||
1213 | * {@inheritdoc} |
||
1214 | */ |
||
1215 | public function supportsCommentOnStatement() |
||
1219 | |||
1220 | /** |
||
1221 | * {@inheritdoc} |
||
1222 | */ |
||
1223 | public function supportsIdentityColumns() |
||
1227 | |||
1228 | /** |
||
1229 | * {@inheritdoc} |
||
1230 | */ |
||
1231 | protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) |
||
1238 | |||
1239 | /** |
||
1240 | * {@inheritdoc} |
||
1241 | */ |
||
1242 | protected function _getCreateTableSQL($tableName, array $columns, array $options = []) |
||
1287 | |||
1288 | /** |
||
1289 | * {@inheritdoc} |
||
1290 | */ |
||
1291 | protected function _getTransactionIsolationLevelSQL($level) |
||
1306 | |||
1307 | /** |
||
1308 | * {@inheritdoc} |
||
1309 | */ |
||
1310 | protected function doModifyLimitQuery($query, $limit, $offset) |
||
1332 | |||
1333 | /** |
||
1334 | * Return the INDEX query section dealing with non-standard |
||
1335 | * SQL Anywhere options. |
||
1336 | * |
||
1337 | * @param Index $index Index definition |
||
1338 | * |
||
1339 | * @return string |
||
1340 | */ |
||
1341 | protected function getAdvancedIndexOptionsSQL(Index $index) |
||
1351 | |||
1352 | /** |
||
1353 | * {@inheritdoc} |
||
1354 | */ |
||
1355 | protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) |
||
1361 | |||
1362 | /** |
||
1363 | * Returns the SQL snippet for creating a table constraint. |
||
1364 | * |
||
1365 | * @param Constraint $constraint The table constraint to create the SQL snippet for. |
||
1366 | * @param string|null $name The table constraint name to use if any. |
||
1367 | * |
||
1368 | * @return string |
||
1369 | * |
||
1370 | * @throws \InvalidArgumentException if the given table constraint type is not supported by this method. |
||
1371 | */ |
||
1372 | protected function getTableConstraintDeclarationSQL(Constraint $constraint, $name = null) |
||
1413 | |||
1414 | /** |
||
1415 | * {@inheritdoc} |
||
1416 | */ |
||
1417 | View Code Duplication | protected function getCreateIndexSQLFlags(Index $index) |
|
1434 | |||
1435 | /** |
||
1436 | * {@inheritdoc} |
||
1437 | */ |
||
1438 | protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) |
||
1444 | |||
1445 | /** |
||
1446 | * {@inheritdoc} |
||
1447 | */ |
||
1448 | protected function getReservedKeywordsClass() |
||
1452 | |||
1453 | /** |
||
1454 | * {@inheritdoc} |
||
1455 | */ |
||
1456 | protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) |
||
1462 | |||
1463 | /** |
||
1464 | * {@inheritdoc} |
||
1465 | */ |
||
1466 | View Code Duplication | protected function initializeDoctrineTypeMappings() |
|
1509 | } |
||
1510 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.