Complex classes like GarbageCollector 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 GarbageCollector, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
43 | class GarbageCollector extends AbstractDataHandlerListener implements SingletonInterface |
||
44 | { |
||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $trackedRecords = []; |
||
49 | |||
50 | /** |
||
51 | * @var TCAService |
||
52 | */ |
||
53 | protected $tcaService; |
||
54 | |||
55 | /** |
||
56 | * GarbageCollector constructor. |
||
57 | * @param TCAService|null $TCAService |
||
58 | */ |
||
59 | 11 | public function __construct(TCAService $TCAService = null) |
|
64 | |||
65 | /** |
||
66 | * Hooks into TCE main and tracks record deletion commands. |
||
67 | * |
||
68 | * @param string $command The command. |
||
69 | * @param string $table The table the record belongs to |
||
70 | * @param int $uid The record's uid |
||
71 | * @param string $value Not used |
||
72 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
73 | * @return void |
||
74 | */ |
||
75 | 2 | public function processCmdmap_preProcess( |
|
93 | |||
94 | /** |
||
95 | * Holds the configuration when a recursive page queing should be triggered. |
||
96 | * |
||
97 | * @var array |
||
98 | * @return array |
||
99 | */ |
||
100 | 3 | protected function getUpdateSubPagesRecursiveTriggerConfiguration() |
|
115 | |||
116 | /** |
||
117 | * Tracks down index documents belonging to a particular record or page and |
||
118 | * removes them from the index and the Index Queue. |
||
119 | * |
||
120 | * @param string $table The record's table name. |
||
121 | * @param int $uid The record's uid. |
||
122 | * @throws \UnexpectedValueException if a hook object does not implement interface \ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor |
||
123 | */ |
||
124 | 10 | public function collectGarbage($table, $uid) |
|
148 | |||
149 | /** |
||
150 | * Tracks down index documents belonging to a particular page and |
||
151 | * removes them from the index and the Index Queue. |
||
152 | * |
||
153 | * @param string $table The record's table name. |
||
154 | * @param int $uid The record's uid. |
||
155 | */ |
||
156 | 10 | protected function collectPageGarbage($table, $uid) |
|
194 | |||
195 | /** |
||
196 | * @param string $table |
||
197 | * @param int $uid |
||
198 | * @param array $changedFields |
||
199 | */ |
||
200 | 3 | protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields) |
|
215 | |||
216 | /** |
||
217 | * Deletes index documents for a given record identification. |
||
218 | * |
||
219 | * @param string $table The record's table name. |
||
220 | * @param int $uid The record's uid. |
||
221 | */ |
||
222 | 10 | protected function deleteIndexDocuments($table, $uid) |
|
244 | |||
245 | /** |
||
246 | * Tracks down index documents belonging to a particular record and |
||
247 | * removes them from the index and the Index Queue. |
||
248 | * |
||
249 | * @param string $table The record's table name. |
||
250 | * @param int $uid The record's uid. |
||
251 | */ |
||
252 | protected function collectRecordGarbage($table, $uid) |
||
257 | |||
258 | // methods checking whether to trigger garbage collection |
||
259 | |||
260 | /** |
||
261 | * Hooks into TCE main and tracks page move commands. |
||
262 | * |
||
263 | * @param string $command The command. |
||
264 | * @param string $table The table the record belongs to |
||
265 | * @param int $uid The record's uid |
||
266 | * @param string $value Not used |
||
267 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
268 | */ |
||
269 | 2 | public function processCmdmap_postProcess( |
|
291 | |||
292 | /** |
||
293 | * Hooks into TCE main and tracks changed records. In this case the current |
||
294 | * record's values are stored to do a change comparison later on for fields |
||
295 | * like fe_group. |
||
296 | * |
||
297 | * @param array $incomingFields An array of incoming fields, new or changed, not used |
||
298 | * @param string $table The table the record belongs to |
||
299 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
300 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
301 | */ |
||
302 | 5 | public function processDatamap_preProcessFieldArray( |
|
343 | |||
344 | /** |
||
345 | * Hooks into TCE Main and watches all record updates. If a change is |
||
346 | * detected that would remove the record from the website, we try to find |
||
347 | * related documents and remove them from the index. |
||
348 | * |
||
349 | * @param string $status Status of the current operation, 'new' or 'update' |
||
350 | * @param string $table The table the record belongs to |
||
351 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
352 | * @param array $fields The record's data, not used |
||
353 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
354 | */ |
||
355 | 7 | public function processDatamap_afterDatabaseOperations( |
|
397 | |||
398 | /** |
||
399 | * Check if a record is getting invisible due to changes in start or endtime. In addition it is checked that the related |
||
400 | * queue item was marked as indexed. |
||
401 | * |
||
402 | * @param string $table |
||
403 | * @param array $record |
||
404 | * @return bool |
||
405 | */ |
||
406 | 3 | protected function isInvisibleByStartOrEndtime($table, $record) |
|
413 | |||
414 | /** |
||
415 | * Checks if the related index queue item is indexed. |
||
416 | * |
||
417 | * * For tt_content and pages_language_overlay the page from the pid is checked |
||
418 | * * For all other records the table it's self is checked |
||
419 | * |
||
420 | * @param string $table The table name. |
||
421 | * @param array $record An array with record fields that may affect visibility. |
||
422 | * @return bool True if the record is marked as being indexed |
||
423 | */ |
||
424 | 2 | protected function isRelatedQueueRecordMarkedAsIndexed($table, $record) |
|
436 | |||
437 | /** |
||
438 | * @return Queue |
||
439 | */ |
||
440 | 10 | private function getIndexQueue() |
|
444 | |||
445 | /** |
||
446 | * Checks whether the a frontend group field exists for the record and if so |
||
447 | * whether groups have been removed from accessing the record thus making |
||
448 | * the record invisible to at least some people. |
||
449 | * |
||
450 | * @param string $table The table name. |
||
451 | * @param array $record An array with record fields that may affect visibility. |
||
452 | * @return bool TRUE if frontend groups have been removed from access to the record, FALSE otherwise. |
||
453 | */ |
||
454 | 1 | protected function hasFrontendGroupsRemoved($table, $record) |
|
473 | |||
474 | /** |
||
475 | * Checks whether the page has been excluded from searching. |
||
476 | * |
||
477 | * @param array $record An array with record fields that may affect visibility. |
||
478 | * @return bool True if the page has been excluded from searching, FALSE otherwise |
||
479 | */ |
||
480 | protected function isPageExcludedFromSearch($record) |
||
484 | |||
485 | /** |
||
486 | * Checks whether a page has a page type that can be indexed. |
||
487 | * Currently standard pages and mount pages can be indexed. |
||
488 | * |
||
489 | * @param array $record A page record |
||
490 | * @return bool TRUE if the page can be indexed according to its page type, FALSE otherwise |
||
491 | */ |
||
492 | protected function isIndexablePageType(array $record) |
||
496 | } |
||
497 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.