Complex classes like tx_t3deploy_databaseController 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 tx_t3deploy_databaseController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class tx_t3deploy_databaseController { |
||
21 | /* |
||
22 | * List of all possible update types: |
||
23 | * + add, change, drop, create_table, change_table, drop_table, clear_table |
||
24 | * List of all sensible update types: |
||
25 | * + add, change, create_table, change_table |
||
26 | */ |
||
27 | const UpdateTypes_List = 'add,change,create_table,change_table'; |
||
|
|||
28 | const RemoveTypes_list = 'drop,drop_table,clear_table'; |
||
29 | |||
30 | /** |
||
31 | * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService |
||
32 | */ |
||
33 | protected $schemaMigrationService; |
||
34 | |||
35 | /** |
||
36 | * @var \TYPO3\CMS\Install\Service\SqlExpectedSchemaService |
||
37 | */ |
||
38 | protected $expectedSchemaService; |
||
39 | |||
40 | /** |
||
41 | * @var \TYPO3\CMS\Core\Category\CategoryRegistry |
||
42 | */ |
||
43 | protected $categoryRegistry; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $consideredTypes; |
||
49 | |||
50 | /** |
||
51 | * Creates this object. |
||
52 | */ |
||
53 | public function __construct() { |
||
63 | |||
64 | /** |
||
65 | * Sets the types considered to be executed (updates and/or removal). |
||
66 | * |
||
67 | * @param array $consideredTypes |
||
68 | * @return void |
||
69 | * @see updateStructureAction() |
||
70 | */ |
||
71 | public function setConsideredTypes(array $consideredTypes) { |
||
74 | |||
75 | /** |
||
76 | * Adds considered types. |
||
77 | * |
||
78 | * @param array $consideredTypes |
||
79 | * @return void |
||
80 | * @see updateStructureAction() |
||
81 | */ |
||
82 | public function addConsideredTypes(array $consideredTypes) { |
||
87 | |||
88 | /** |
||
89 | * Removes defined types from considered types. |
||
90 | * |
||
91 | * @param array $removals |
||
92 | * @return void |
||
93 | * @see updateStructureAction() |
||
94 | */ |
||
95 | public function removeConsideredTypes(array $removals) { |
||
98 | |||
99 | /** |
||
100 | * Updates the database structure. |
||
101 | * |
||
102 | * @param array $arguments Optional arguments passed to this action |
||
103 | * @return string |
||
104 | */ |
||
105 | public function updateStructureAction(array $arguments) { |
||
134 | |||
135 | /** |
||
136 | * call executeUpdateStructure until there are no more changes. |
||
137 | * |
||
138 | * The install tool sometimes relies on the user hitting the "update" button multiple times. This method |
||
139 | * encapsulates that behaviour. |
||
140 | * |
||
141 | * @see executeUpdateStructure() |
||
142 | * @param array $arguments |
||
143 | * @param bool $allowKeyModifications |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function executeUpdateStructureUntilNoMoreChanges(array $arguments, $allowKeyModifications = FALSE) { |
||
167 | |||
168 | /** |
||
169 | * Executes the database structure updates. |
||
170 | * |
||
171 | * @param array $arguments Optional arguments passed to this action |
||
172 | * @param boolean $allowKeyModifications Whether to allow key modifications |
||
173 | * @return string |
||
174 | */ |
||
175 | protected function executeUpdateStructure(array $arguments, $allowKeyModifications = FALSE) { |
||
233 | |||
234 | /** |
||
235 | * performs some basic checks on the database changes to identify most common errors |
||
236 | * |
||
237 | * @param string $changes the changes to check |
||
238 | * @throws Exception if the file seems to contain bad data |
||
239 | */ |
||
240 | protected function checkChangesSyntax($changes) { |
||
247 | |||
248 | /** |
||
249 | * Removes key modifications that will cause errors. |
||
250 | * |
||
251 | * @param array $differences The differences to be cleaned up |
||
252 | * @return array The cleaned differences |
||
253 | */ |
||
254 | protected function removeKeyModifications(array $differences) { |
||
260 | |||
261 | /** |
||
262 | * Unsets a subkey in a given differences array. |
||
263 | * |
||
264 | * @param array $differences |
||
265 | * @param string $type e.g. extra or diff |
||
266 | * @param string $subKey e.g. keys or fields |
||
267 | * @param string $exception e.g. whole_table that stops the removal |
||
268 | * @return array |
||
269 | */ |
||
270 | protected function unsetSubKey(array $differences, $type, $subKey, $exception = '') { |
||
282 | |||
283 | /** |
||
284 | * Gets the differences in the database structure by comparing |
||
285 | * the current structure with the SQL definitions of all extensions |
||
286 | * and the TYPO3 core in t3lib/stddb/tables.sql. |
||
287 | * |
||
288 | * This method searches for fields/tables to be added/updated. |
||
289 | * |
||
290 | * @param boolean $allowKeyModifications Whether to allow key modifications |
||
291 | * @return array The database statements to update the structure |
||
292 | */ |
||
293 | protected function getStructureDifferencesForUpdate($allowKeyModifications = FALSE) { |
||
305 | |||
306 | /** |
||
307 | * Gets the differences in the database structure by comparing |
||
308 | * the current structure with the SQL definitions of all extensions |
||
309 | * and the TYPO3 core in t3lib/stddb/tables.sql. |
||
310 | * |
||
311 | * This method searches for fields/tables to be removed. |
||
312 | * |
||
313 | * @param boolean $allowKeyModifications Whether to allow key modifications |
||
314 | * @return array The database statements to update the structure |
||
315 | */ |
||
316 | protected function getStructureDifferencesForRemoval($allowKeyModifications = FALSE) { |
||
328 | |||
329 | /** |
||
330 | * Gets the defined field definitions from the ext_tables.sql files. |
||
331 | * |
||
332 | * @return array The accordant definitions |
||
333 | */ |
||
334 | protected function getDefinedFieldDefinitions() { |
||
341 | |||
342 | /** |
||
343 | * Gets all structure definitions of extensions the TYPO3 Core. |
||
344 | * |
||
345 | * @return array All structure definitions |
||
346 | */ |
||
347 | protected function getAllRawStructureDefinitions() { |
||
354 | |||
355 | /** |
||
356 | * Gets the defined update types. |
||
357 | * |
||
358 | * @return array |
||
359 | */ |
||
360 | protected function getUpdateTypes() { |
||
363 | |||
364 | /** |
||
365 | * Gets the defined remove types. |
||
366 | * |
||
367 | * @return array |
||
368 | */ |
||
369 | protected function getRemoveTypes() { |
||
372 | |||
373 | /** |
||
374 | * sorts the statements in an array |
||
375 | * |
||
376 | * @param array $statements |
||
377 | * @return array |
||
378 | */ |
||
379 | protected function sortStatements($statements) { |
||
394 | |||
395 | /** |
||
396 | * returns true if the given statement looks as if it drops a (primary) key |
||
397 | * |
||
398 | * @param $statement |
||
399 | * @return bool |
||
400 | */ |
||
401 | protected function isDropKeyStatement($statement) { |
||
404 | } |
||
405 |