Complex classes like DB2Platform 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 DB2Platform, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class DB2Platform extends AbstractPlatform |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * {@inheritDoc} |
||
| 27 | */ |
||
| 28 | 2063 | public function getBlobTypeDeclarationSQL(array $field) : string |
|
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritDoc} |
||
| 36 | 1761 | */ |
|
| 37 | public function initializeDoctrineTypeMappings() : void |
||
| 57 | |||
| 58 | /** |
||
| 59 | 2184 | * {@inheritdoc} |
|
| 60 | */ |
||
| 61 | public function isCommentedDoctrineType(Type $doctrineType) : bool |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritDoc} |
||
| 74 | 2024 | */ |
|
| 75 | protected function getBinaryTypeDeclarationSQLSnippet(?int $length) : string |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritDoc} |
||
| 82 | */ |
||
| 83 | protected function getVarbinaryTypeDeclarationSQLSnippet(?int $length) : string |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritDoc} |
||
| 90 | */ |
||
| 91 | public function getClobTypeDeclarationSQL(array $field) : string |
||
| 96 | |||
| 97 | /** |
||
| 98 | 2250 | * {@inheritDoc} |
|
| 99 | */ |
||
| 100 | 2250 | public function getName() : string |
|
| 104 | |||
| 105 | /** |
||
| 106 | 2248 | * {@inheritDoc} |
|
| 107 | */ |
||
| 108 | public function getBooleanTypeDeclarationSQL(array $columnDef) : string |
||
| 112 | 2186 | ||
| 113 | /** |
||
| 114 | 2186 | * {@inheritDoc} |
|
| 115 | 2186 | */ |
|
| 116 | public function getIntegerTypeDeclarationSQL(array $columnDef) : string |
||
| 120 | |||
| 121 | 1757 | /** |
|
| 122 | * {@inheritDoc} |
||
| 123 | 1757 | */ |
|
| 124 | public function getBigIntTypeDeclarationSQL(array $columnDef) : string |
||
| 128 | |||
| 129 | 2100 | /** |
|
| 130 | * {@inheritDoc} |
||
| 131 | */ |
||
| 132 | 2100 | public function getSmallIntTypeDeclarationSQL(array $columnDef) : string |
|
| 136 | |||
| 137 | /** |
||
| 138 | 2190 | * {@inheritDoc} |
|
| 139 | */ |
||
| 140 | 2190 | protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) : string |
|
| 149 | |||
| 150 | /** |
||
| 151 | * {@inheritdoc} |
||
| 152 | */ |
||
| 153 | public function getBitAndComparisonExpression(string $value1, string $value2) : string |
||
| 157 | |||
| 158 | /** |
||
| 159 | * {@inheritdoc} |
||
| 160 | */ |
||
| 161 | public function getBitOrComparisonExpression(string $value1, string $value2) : string |
||
| 165 | |||
| 166 | /** |
||
| 167 | * {@inheritdoc} |
||
| 168 | */ |
||
| 169 | protected function getDateArithmeticIntervalExpression(string $date, string $operator, string $interval, string $unit) : string |
||
| 185 | 2190 | ||
| 186 | /** |
||
| 187 | * {@inheritdoc} |
||
| 188 | */ |
||
| 189 | public function getDateDiffExpression(string $date1, string $date2) : string |
||
| 193 | 1121 | ||
| 194 | /** |
||
| 195 | * {@inheritDoc} |
||
| 196 | */ |
||
| 197 | public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) : string |
||
| 205 | |||
| 206 | /** |
||
| 207 | 1987 | * {@inheritDoc} |
|
| 208 | */ |
||
| 209 | public function getDateTypeDeclarationSQL(array $fieldDeclaration) : string |
||
| 213 | 1987 | ||
| 214 | /** |
||
| 215 | 1987 | * {@inheritDoc} |
|
| 216 | 1987 | */ |
|
| 217 | 1987 | public function getTimeTypeDeclarationSQL(array $fieldDeclaration) : string |
|
| 221 | 1987 | ||
| 222 | /** |
||
| 223 | * {@inheritdoc} |
||
| 224 | */ |
||
| 225 | public function getTruncateTableSQL(string $tableName, bool $cascade = false) : string |
||
| 231 | |||
| 232 | /** |
||
| 233 | * This code fragment is originally from the Zend_Db_Adapter_Db2 class, but has been edited. |
||
| 234 | */ |
||
| 235 | 2084 | public function getListTableColumnsSQL(string $table, ?string $database = null) : string |
|
| 282 | |||
| 283 | /** |
||
| 284 | * {@inheritDoc} |
||
| 285 | */ |
||
| 286 | public function getListTablesSQL() : string |
||
| 290 | |||
| 291 | /** |
||
| 292 | * {@inheritDoc} |
||
| 293 | */ |
||
| 294 | public function getListViewsSQL(string $database) : string |
||
| 298 | |||
| 299 | /** |
||
| 300 | * {@inheritDoc} |
||
| 301 | */ |
||
| 302 | public function getListTableIndexesSQL(string $table, ?string $currentDatabase = null) : string |
||
| 322 | |||
| 323 | /** |
||
| 324 | * {@inheritDoc} |
||
| 325 | */ |
||
| 326 | public function getListTableForeignKeysSQL(string $table, ?string $database = null) : string |
||
| 356 | |||
| 357 | /** |
||
| 358 | * {@inheritDoc} |
||
| 359 | */ |
||
| 360 | public function getCreateViewSQL(string $name, string $sql) : string |
||
| 364 | |||
| 365 | /** |
||
| 366 | * {@inheritDoc} |
||
| 367 | */ |
||
| 368 | public function getDropViewSQL(string $name) : string |
||
| 372 | |||
| 373 | /** |
||
| 374 | * {@inheritDoc} |
||
| 375 | */ |
||
| 376 | public function getCreateDatabaseSQL(string $database) : string |
||
| 380 | |||
| 381 | /** |
||
| 382 | * {@inheritDoc} |
||
| 383 | */ |
||
| 384 | public function getDropDatabaseSQL(string $database) : string |
||
| 388 | |||
| 389 | /** |
||
| 390 | * {@inheritDoc} |
||
| 391 | */ |
||
| 392 | public function supportsCreateDropDatabase() : bool |
||
| 396 | 1488 | ||
| 397 | /** |
||
| 398 | * {@inheritDoc} |
||
| 399 | */ |
||
| 400 | public function supportsReleaseSavepoints() : bool |
||
| 404 | |||
| 405 | 1977 | /** |
|
| 406 | * {@inheritdoc} |
||
| 407 | */ |
||
| 408 | public function supportsCommentOnStatement() : bool |
||
| 412 | |||
| 413 | 1977 | /** |
|
| 414 | * {@inheritDoc} |
||
| 415 | */ |
||
| 416 | public function getCurrentDateSQL() : string |
||
| 420 | |||
| 421 | 1877 | /** |
|
| 422 | * {@inheritDoc} |
||
| 423 | */ |
||
| 424 | public function getCurrentTimeSQL() : string |
||
| 428 | |||
| 429 | 1877 | /** |
|
| 430 | * {@inheritDoc} |
||
| 431 | */ |
||
| 432 | public function getCurrentTimestampSQL() : string |
||
| 436 | |||
| 437 | 248 | /** |
|
| 438 | * {@inheritDoc} |
||
| 439 | */ |
||
| 440 | public function getIndexDeclarationSQL(string $name, Index $index) : string |
||
| 445 | 2 | ||
| 446 | /** |
||
| 447 | * {@inheritDoc} |
||
| 448 | */ |
||
| 449 | protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array |
||
| 465 | |||
| 466 | /** |
||
| 467 | 1964 | * {@inheritDoc} |
|
| 468 | */ |
||
| 469 | 1964 | public function getAlterTableSQL(TableDiff $diff) : array |
|
| 579 | 996 | ||
| 580 | /** |
||
| 581 | * Gathers the table alteration SQL for a given column diff. |
||
| 582 | * |
||
| 583 | 996 | * @param Identifier $table The table to gather the SQL for. |
|
| 584 | * @param ColumnDiff $columnDiff The column diff to evaluate. |
||
| 585 | 996 | * @param string[] $sql The sequence of table alteration statements to fill. |
|
| 586 | 996 | * @param mixed[] $queryParts The sequence of column alteration clauses to fill. |
|
| 587 | */ |
||
| 588 | private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts) : void |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Returns the ALTER COLUMN SQL clauses for altering a column described by the given column diff. |
||
| 613 | 1808 | * |
|
| 614 | 1808 | * @param ColumnDiff $columnDiff The column diff to evaluate. |
|
| 615 | 1808 | * |
|
| 616 | 1808 | * @return string[] |
|
| 617 | */ |
||
| 618 | private function getAlterColumnClausesSQL(ColumnDiff $columnDiff) : array |
||
| 657 | |||
| 658 | /** |
||
| 659 | * {@inheritDoc} |
||
| 660 | */ |
||
| 661 | 1783 | protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) : array |
|
| 690 | 1562 | ||
| 691 | 1562 | /** |
|
| 692 | * {@inheritdoc} |
||
| 693 | */ |
||
| 694 | 1510 | protected function getRenameIndexSQL(string $oldIndexName, Index $index, string $tableName) : array |
|
| 703 | |||
| 704 | 1808 | /** |
|
| 705 | * {@inheritDoc} |
||
| 706 | 1808 | */ |
|
| 707 | 1808 | public function getDefaultValueDeclarationSQL(array $field) : string |
|
| 721 | |||
| 722 | /** |
||
| 723 | * {@inheritDoc} |
||
| 724 | */ |
||
| 725 | public function getEmptyIdentityInsertSQL(string $tableName, string $identifierColumnName) : string |
||
| 729 | 1808 | ||
| 730 | /** |
||
| 731 | 1808 | * {@inheritDoc} |
|
| 732 | */ |
||
| 733 | public function getCreateTemporaryTableSnippetSQL() : string |
||
| 737 | 522 | ||
| 738 | /** |
||
| 739 | 522 | * {@inheritDoc} |
|
| 740 | 279 | */ |
|
| 741 | 279 | public function getTemporaryTableName(string $tableName) : string |
|
| 745 | |||
| 746 | /** |
||
| 747 | * {@inheritDoc} |
||
| 748 | */ |
||
| 749 | protected function doModifyLimitQuery(string $query, ?int $limit, int $offset) : string |
||
| 772 | |||
| 773 | /** |
||
| 774 | * {@inheritDoc} |
||
| 775 | */ |
||
| 776 | 1918 | public function getLocateExpression(string $string, string $substring, ?string $start = null) : string |
|
| 784 | 116 | ||
| 785 | /** |
||
| 786 | 116 | * {@inheritDoc} |
|
| 787 | */ |
||
| 788 | public function getSubstringExpression(string $string, string $start, ?string $length = null) : string |
||
| 796 | 1959 | ||
| 797 | 1957 | /** |
|
| 798 | * {@inheritDoc} |
||
| 799 | */ |
||
| 800 | 1959 | public function getCurrentDatabaseExpression() : string |
|
| 804 | 1959 | ||
| 805 | 1953 | /** |
|
| 806 | * {@inheritDoc} |
||
| 807 | */ |
||
| 808 | public function supportsIdentityColumns() : bool |
||
| 812 | 1957 | ||
| 813 | /** |
||
| 814 | * {@inheritDoc} |
||
| 815 | */ |
||
| 816 | public function prefersIdentityColumns() : bool |
||
| 820 | |||
| 821 | 1986 | /** |
|
| 822 | 1986 | * {@inheritDoc} |
|
| 823 | * |
||
| 824 | * DB2 returns all column names in SQL result sets in uppercase. |
||
| 825 | 1986 | */ |
|
| 826 | public function getSQLResultCasing(string $column) : string |
||
| 830 | |||
| 831 | 1827 | /** |
|
| 832 | * {@inheritDoc} |
||
| 833 | 1827 | */ |
|
| 834 | 1827 | public function getForUpdateSQL() : string |
|
| 838 | |||
| 839 | /** |
||
| 840 | * {@inheritDoc} |
||
| 841 | */ |
||
| 842 | public function getDummySelectSQL(string $expression = '1') : string |
||
| 846 | |||
| 847 | /** |
||
| 848 | * {@inheritDoc} |
||
| 849 | * |
||
| 850 | * DB2 supports savepoints, but they work semantically different than on other vendor platforms. |
||
| 851 | 1794 | * |
|
| 852 | * TODO: We have to investigate how to get DB2 up and running with savepoints. |
||
| 853 | 1794 | */ |
|
| 854 | public function supportsSavepoints() : bool |
||
| 858 | |||
| 859 | /** |
||
| 860 | * {@inheritDoc} |
||
| 861 | 1752 | */ |
|
| 862 | protected function getReservedKeywordsClass() : string |
||
| 866 | |||
| 867 | public function getListTableCommentsSQL(string $table) : string |
||
| 879 | } |
||
| 880 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..