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 | 10 | 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 | 3 | * @return array |
|
99 | */ |
||
100 | 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 | 10 | * @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 | 10 | * @param int $uid The record's uid. |
|
155 | */ |
||
156 | protected function collectPageGarbage($table, $uid) |
||
187 | |||
188 | /** |
||
189 | * @param string $table |
||
190 | * @param int $uid |
||
191 | 3 | * @param array $changedFields |
|
192 | */ |
||
193 | 3 | protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields) |
|
208 | |||
209 | /** |
||
210 | * Deletes index documents for a given record identification. |
||
211 | * |
||
212 | * @param string $table The record's table name. |
||
213 | 10 | * @param int $uid The record's uid. |
|
214 | */ |
||
215 | protected function deleteIndexDocuments($table, $uid) |
||
237 | |||
238 | /** |
||
239 | * Tracks down index documents belonging to a particular record and |
||
240 | * removes them from the index and the Index Queue. |
||
241 | * |
||
242 | * @param string $table The record's table name. |
||
243 | * @param int $uid The record's uid. |
||
244 | */ |
||
245 | protected function collectRecordGarbage($table, $uid) |
||
250 | |||
251 | // methods checking whether to trigger garbage collection |
||
252 | |||
253 | /** |
||
254 | * Hooks into TCE main and tracks page move commands. |
||
255 | * |
||
256 | * @param string $command The command. |
||
257 | * @param string $table The table the record belongs to |
||
258 | * @param int $uid The record's uid |
||
259 | * @param string $value Not used |
||
260 | 2 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
|
261 | */ |
||
262 | public function processCmdmap_postProcess( |
||
284 | |||
285 | /** |
||
286 | * Hooks into TCE main and tracks changed records. In this case the current |
||
287 | * record's values are stored to do a change comparison later on for fields |
||
288 | * like fe_group. |
||
289 | * |
||
290 | * @param array $incomingFields An array of incoming fields, new or changed, not used |
||
291 | 4 | * @param string $table The table the record belongs to |
|
292 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
293 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
294 | */ |
||
295 | public function processDatamap_preProcessFieldArray( |
||
336 | |||
337 | /** |
||
338 | * Hooks into TCE Main and watches all record updates. If a change is |
||
339 | * detected that would remove the record from the website, we try to find |
||
340 | * related documents and remove them from the index. |
||
341 | * |
||
342 | 6 | * @param string $status Status of the current operation, 'new' or 'update' |
|
343 | * @param string $table The table the record belongs to |
||
344 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
345 | * @param array $fields The record's data, not used |
||
346 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
347 | */ |
||
348 | public function processDatamap_afterDatabaseOperations( |
||
390 | |||
391 | /** |
||
392 | 2 | * Check if a record is getting invisible due to changes in start or endtime. In addition it is checked that the related |
|
393 | * queue item was marked as indexed. |
||
394 | * |
||
395 | 2 | * @param string $table |
|
396 | 2 | * @param array $record |
|
397 | * @return bool |
||
398 | */ |
||
399 | protected function isInvisibleByStartOrEndtime($table, $record) |
||
406 | |||
407 | /** |
||
408 | * Checks if the related index queue item is indexed. |
||
409 | * |
||
410 | 2 | * * For tt_content and pages_language_overlay the page from the pid is checked |
|
411 | * * For all other records the table it's self is checked |
||
412 | 2 | * |
|
413 | 2 | * @param string $table The table name. |
|
414 | 2 | * @param array $record An array with record fields that may affect visibility. |
|
415 | * @return bool True if the record is marked as being indexed |
||
416 | */ |
||
417 | protected function isRelatedQueueRecordMarkedAsIndexed($table, $record) |
||
428 | |||
429 | /** |
||
430 | * @return Queue |
||
431 | */ |
||
432 | private function getIndexQueue() |
||
436 | |||
437 | /** |
||
438 | * Checks whether the a frontend group field exists for the record and if so |
||
439 | * whether groups have been removed from accessing the record thus making |
||
440 | * the record invisible to at least some people. |
||
441 | * |
||
442 | * @param string $table The table name. |
||
443 | * @param array $record An array with record fields that may affect visibility. |
||
444 | * @return bool TRUE if frontend groups have been removed from access to the record, FALSE otherwise. |
||
445 | */ |
||
446 | protected function hasFrontendGroupsRemoved($table, $record) |
||
465 | |||
466 | /** |
||
467 | * Checks whether the page has been excluded from searching. |
||
468 | * |
||
469 | * @param array $record An array with record fields that may affect visibility. |
||
470 | * @return bool True if the page has been excluded from searching, FALSE otherwise |
||
471 | */ |
||
472 | protected function isPageExcludedFromSearch($record) |
||
476 | |||
477 | /** |
||
478 | * Checks whether a page has a page type that can be indexed. |
||
479 | * Currently standard pages and mount pages can be indexed. |
||
480 | * |
||
481 | * @param array $record A page record |
||
482 | * @return bool TRUE if the page can be indexed according to its page type, FALSE otherwise |
||
483 | */ |
||
484 | protected function isIndexablePageType(array $record) |
||
488 | |||
489 | /** |
||
490 | * Cleans an index from garbage entries. |
||
491 | * |
||
492 | * Was used to clean the index from expired documents/past endtime. Solr 4.8 |
||
493 | * introduced DocExpirationUpdateProcessor to do that job by itself. |
||
494 | * |
||
495 | * The method remains as a dummy for possible later cleanups and to prevent |
||
496 | * things from breaking if others were using it. |
||
497 | * |
||
498 | * @deprecated since 6.0 will be removed in 7.0. deletion is done by DocExpirationUpdateProcessor |
||
499 | * @param Site $site The site to clean indexes on |
||
500 | * @param bool $commitAfterCleanUp Whether to commit right after the clean up, defaults to TRUE |
||
501 | * @return void |
||
502 | */ |
||
503 | public function cleanIndex(Site $site, $commitAfterCleanUp = true) |
||
507 | } |
||
508 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.