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 |
||
44 | class GarbageCollector extends AbstractDataHandlerListener implements SingletonInterface |
||
45 | { |
||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $trackedRecords = []; |
||
50 | |||
51 | /** |
||
52 | * @var TCAService |
||
53 | */ |
||
54 | protected $tcaService; |
||
55 | |||
56 | /** |
||
57 | * GarbageCollector constructor. |
||
58 | * @param TCAService|null $TCAService |
||
59 | */ |
||
60 | 4 | 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 | public function processCmdmap_preProcess( |
||
91 | |||
92 | /** |
||
93 | * Holds the configuration when a recursive page queing should be triggered. |
||
94 | * |
||
95 | * @var array |
||
96 | * @return array |
||
97 | */ |
||
98 | 2 | protected function getUpdateSubPagesRecursiveTriggerConfiguration() |
|
113 | |||
114 | /** |
||
115 | * Tracks down index documents belonging to a particular record or page and |
||
116 | * removes them from the index and the Index Queue. |
||
117 | * |
||
118 | * @param string $table The record's table name. |
||
119 | * @param int $uid The record's uid. |
||
120 | * @throws \UnexpectedValueException if a hook object does not implement interface \ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor |
||
121 | */ |
||
122 | 4 | public function collectGarbage($table, $uid) |
|
146 | |||
147 | /** |
||
148 | * Tracks down index documents belonging to a particular page and |
||
149 | * removes them from the index and the Index Queue. |
||
150 | * |
||
151 | * @param string $table The record's table name. |
||
152 | * @param int $uid The record's uid. |
||
153 | */ |
||
154 | 4 | protected function collectPageGarbage($table, $uid) |
|
185 | |||
186 | /** |
||
187 | * @param string $table |
||
188 | * @param int $uid |
||
189 | * @param array $changedFields |
||
190 | */ |
||
191 | 2 | protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields) |
|
206 | |||
207 | /** |
||
208 | * Deletes index documents for a given record identification. |
||
209 | * |
||
210 | * @param string $table The record's table name. |
||
211 | * @param int $uid The record's uid. |
||
212 | */ |
||
213 | 4 | protected function deleteIndexDocuments($table, $uid) |
|
235 | |||
236 | /** |
||
237 | * Tracks down index documents belonging to a particular record and |
||
238 | * removes them from the index and the Index Queue. |
||
239 | * |
||
240 | * @param string $table The record's table name. |
||
241 | * @param int $uid The record's uid. |
||
242 | */ |
||
243 | protected function collectRecordGarbage($table, $uid) |
||
248 | |||
249 | // methods checking whether to trigger garbage collection |
||
250 | |||
251 | /** |
||
252 | * Hooks into TCE main and tracks page move commands. |
||
253 | * |
||
254 | * @param string $command The command. |
||
255 | * @param string $table The table the record belongs to |
||
256 | * @param int $uid The record's uid |
||
257 | * @param string $value Not used |
||
258 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
259 | */ |
||
260 | public function processCmdmap_postProcess( |
||
280 | |||
281 | /** |
||
282 | * Hooks into TCE main and tracks changed records. In this case the current |
||
283 | * record's values are stored to do a change comparison later on for fields |
||
284 | * like fe_group. |
||
285 | * |
||
286 | * @param array $incomingFields An array of incoming fields, new or changed, not used |
||
287 | * @param string $table The table the record belongs to |
||
288 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
289 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
290 | */ |
||
291 | public function processDatamap_preProcessFieldArray( |
||
324 | |||
325 | /** |
||
326 | * Hooks into TCE Main and watches all record updates. If a change is |
||
327 | * detected that would remove the record from the website, we try to find |
||
328 | * related documents and remove them from the index. |
||
329 | * |
||
330 | * @param string $status Status of the current operation, 'new' or 'update' |
||
331 | * @param string $table The table the record belongs to |
||
332 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
333 | * @param array $fields The record's data, not used |
||
334 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
335 | */ |
||
336 | 2 | public function processDatamap_afterDatabaseOperations( |
|
371 | |||
372 | /** |
||
373 | 2 | * Check if a record is getting invisible due to changes in start or endtime. In addition it is checked that the related |
|
374 | * queue item was marked as indexed. |
||
375 | * |
||
376 | * @param string $table |
||
377 | * @param array $record |
||
378 | * @return bool |
||
379 | */ |
||
380 | protected function isInvisibleByStartOrEndtime($table, $record) |
||
387 | |||
388 | /** |
||
389 | * Checks if the related index queue item is indexed. |
||
390 | * |
||
391 | 4 | * * For tt_content and pages_language_overlay the page from the pid is checked |
|
392 | * * For all other records the table it's self is checked |
||
393 | 4 | * |
|
394 | * @param string $table The table name. |
||
395 | * @param array $record An array with record fields that may affect visibility. |
||
396 | * @return bool True if the record is marked as being indexed |
||
397 | */ |
||
398 | protected function isRelatedQueueRecordMarkedAsIndexed($table, $record) |
||
409 | |||
410 | /** |
||
411 | * @return Queue |
||
412 | */ |
||
413 | private function getIndexQueue() |
||
417 | |||
418 | /** |
||
419 | * Checks whether the a frontend group field exists for the record and if so |
||
420 | * whether groups have been removed from accessing the record thus making |
||
421 | * the record invisible to at least some people. |
||
422 | * |
||
423 | * @param string $table The table name. |
||
424 | * @param array $record An array with record fields that may affect visibility. |
||
425 | * @return bool TRUE if frontend groups have been removed from access to the record, FALSE otherwise. |
||
426 | */ |
||
427 | protected function hasFrontendGroupsRemoved($table, $record) |
||
446 | |||
447 | /** |
||
448 | * Checks whether the page has been excluded from searching. |
||
449 | * |
||
450 | * @param array $record An array with record fields that may affect visibility. |
||
451 | * @return bool True if the page has been excluded from searching, FALSE otherwise |
||
452 | */ |
||
453 | protected function isPageExcludedFromSearch($record) |
||
457 | |||
458 | /** |
||
459 | * Checks whether a page has a page type that can be indexed. |
||
460 | * Currently standard pages and mount pages can be indexed. |
||
461 | * |
||
462 | * @param array $record A page record |
||
463 | * @return bool TRUE if the page can be indexed according to its page type, FALSE otherwise |
||
464 | */ |
||
465 | protected function isIndexablePageType(array $record) |
||
469 | |||
470 | /** |
||
471 | * Cleans an index from garbage entries. |
||
472 | * |
||
473 | * Was used to clean the index from expired documents/past endtime. Solr 4.8 |
||
474 | * introduced DocExpirationUpdateProcessor to do that job by itself. |
||
475 | * |
||
476 | * The method remains as a dummy for possible later cleanups and to prevent |
||
477 | * things from breaking if others were using it. |
||
478 | * |
||
479 | * @deprecated since 6.0 will be removed in 7.0. deletion is done by DocExpirationUpdateProcessor |
||
480 | * @param Site $site The site to clean indexes on |
||
481 | * @param bool $commitAfterCleanUp Whether to commit right after the clean up, defaults to TRUE |
||
482 | * @return void |
||
483 | */ |
||
484 | public function cleanIndex(Site $site, $commitAfterCleanUp = true) |
||
488 | } |
||
489 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.