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 | protected $trackedRecords = array(); |
||
46 | |||
47 | /** |
||
48 | * Hooks into TCE main and tracks record deletion commands. |
||
49 | * |
||
50 | * @param string $command The command. |
||
51 | * @param string $table The table the record belongs to |
||
52 | * @param int $uid The record's uid |
||
53 | * @param string $value Not used |
||
54 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
55 | * @return void |
||
56 | */ |
||
57 | public function processCmdmap_preProcess( |
||
73 | |||
74 | /** |
||
75 | * Holds the configuration when a recursive page queing should be triggered. |
||
76 | * |
||
77 | * @var array |
||
78 | * @return array |
||
79 | */ |
||
80 | 2 | protected function getUpdateSubPagesRecursiveTriggerConfiguration() |
|
81 | { |
||
82 | return array( |
||
83 | // the current page has the field "extendToSubpages" enabled and the field "hidden" was set to 1 |
||
84 | 'extendToSubpageEnabledAndHiddenFlagWasAdded' => array( |
||
85 | 'currentState' => array('extendToSubpages' => '1'), |
||
86 | 'changeSet' => array('hidden' => '1') |
||
87 | 2 | ), |
|
88 | // the current page has the field "hidden" enabled and the field "extendToSubpages" was set to 1 |
||
89 | 'hiddenIsEnabledAndExtendToSubPagesWasAdded' => array( |
||
90 | 'currentState' => array('hidden' => '1'), |
||
91 | 'changeSet' => array('extendToSubpages' => '1') |
||
92 | ) |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Tracks down index documents belonging to a particular record or page and |
||
98 | * removes them from the index and the Index Queue. |
||
99 | * |
||
100 | * @param string $table The record's table name. |
||
101 | * @param int $uid The record's uid. |
||
102 | * @throws \UnexpectedValueException if a hook object does not implement interface \ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor |
||
103 | */ |
||
104 | 4 | public function collectGarbage($table, $uid) |
|
105 | { |
||
106 | 4 | if ($table == 'tt_content' || $table == 'pages' || $table == 'pages_language_overlay') { |
|
107 | 4 | $this->collectPageGarbage($table, $uid); |
|
108 | } else { |
||
109 | $this->collectRecordGarbage($table, $uid); |
||
110 | } |
||
111 | |||
112 | 4 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessGarbageCollector'])) { |
|
113 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessGarbageCollector'] as $classReference) { |
||
114 | $garbageCollectorPostProcessor = GeneralUtility::getUserObj($classReference); |
||
115 | |||
116 | if ($garbageCollectorPostProcessor instanceof GarbageCollectorPostProcessor) { |
||
117 | $garbageCollectorPostProcessor->postProcessGarbageCollector($table, |
||
118 | $uid); |
||
119 | } else { |
||
120 | throw new \UnexpectedValueException( |
||
121 | get_class($garbageCollectorPostProcessor) . ' must implement interface ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor', |
||
122 | 1345807460 |
||
123 | ); |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | 4 | } |
|
128 | |||
129 | /** |
||
130 | * Tracks down index documents belonging to a particular page and |
||
131 | * removes them from the index and the Index Queue. |
||
132 | * |
||
133 | * @param string $table The record's table name. |
||
134 | * @param int $uid The record's uid. |
||
135 | */ |
||
136 | 4 | protected function collectPageGarbage($table, $uid) |
|
167 | |||
168 | /** |
||
169 | * @param string $table |
||
170 | * @param int $uid |
||
171 | * @param array $changedFields |
||
172 | */ |
||
173 | 2 | protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields) |
|
188 | |||
189 | /** |
||
190 | * Deletes index documents for a given record identification. |
||
191 | * |
||
192 | * @param string $table The record's table name. |
||
193 | * @param int $uid The record's uid. |
||
194 | */ |
||
195 | 4 | protected function deleteIndexDocuments($table, $uid) |
|
217 | |||
218 | /** |
||
219 | * Tracks down index documents belonging to a particular record and |
||
220 | * removes them from the index and the Index Queue. |
||
221 | * |
||
222 | * @param string $table The record's table name. |
||
223 | * @param int $uid The record's uid. |
||
224 | */ |
||
225 | protected function collectRecordGarbage($table, $uid) |
||
230 | |||
231 | // methods checking whether to trigger garbage collection |
||
232 | |||
233 | /** |
||
234 | * Hooks into TCE main and tracks page move commands. |
||
235 | * |
||
236 | * @param string $command The command. |
||
237 | * @param string $table The table the record belongs to |
||
238 | * @param int $uid The record's uid |
||
239 | * @param string $value Not used |
||
240 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
241 | */ |
||
242 | public function processCmdmap_postProcess( |
||
262 | |||
263 | /** |
||
264 | * Hooks into TCE main and tracks changed records. In this case the current |
||
265 | * record's values are stored to do a change comparison later on for fields |
||
266 | * like fe_group. |
||
267 | * |
||
268 | * @param array $incomingFields An array of incoming fields, new or changed, not used |
||
269 | * @param string $table The table the record belongs to |
||
270 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
||
271 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
272 | */ |
||
273 | public function processDatamap_preProcessFieldArray( |
||
308 | |||
309 | /** |
||
310 | * Compiles a list of visibility affecting fields of a table so that it can |
||
311 | * be used in SQL queries. |
||
312 | 2 | * |
|
313 | * @param string $table Table name to retrieve visibility affecting fields for |
||
314 | 2 | * @return string Comma separated list of field names that affect the visibility of a record on the website |
|
315 | */ |
||
316 | 2 | protected function getVisibilityAffectingFieldsByTable($table) |
|
342 | |||
343 | /** |
||
344 | * Makes sure that "empty" frontend group fields are always the same value. |
||
345 | * |
||
346 | 2 | * @param string $table The record's table name. |
|
347 | * @param array $record the record array. |
||
348 | 2 | * @return array The cleaned record |
|
349 | 2 | */ |
|
350 | protected function normalizeFrontendGroupField($table, $record) |
||
362 | |||
363 | /** |
||
364 | * Hooks into TCE Main and watches all record updates. If a change is |
||
365 | * detected that would remove the record from the website, we try to find |
||
366 | * related documents and remove them from the index. |
||
367 | * |
||
368 | * @param string $status Status of the current operation, 'new' or 'update' |
||
369 | * @param string $table The table the record belongs to |
||
370 | 2 | * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
|
371 | * @param array $fields The record's data, not used |
||
372 | * @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
||
373 | */ |
||
374 | public function processDatamap_afterDatabaseOperations( |
||
413 | |||
414 | /** |
||
415 | * Checks whether a hidden field exists for the current table and if so |
||
416 | * determines whether it is set on the current record. |
||
417 | * |
||
418 | 2 | * @param string $table The table name. |
|
419 | * @param array $record An array with record fields that may affect visibility. |
||
420 | 2 | * @return bool True if the record is hidden, FALSE otherwise. |
|
421 | */ |
||
422 | 2 | protected function isHidden($table, $record) |
|
433 | |||
434 | /** |
||
435 | * Checks whether a start time field exists for the record's table and if so |
||
436 | * determines if a time is set and whether that time is in the future, |
||
437 | * making the record invisible on the website. |
||
438 | * |
||
439 | * @param string $table The table name. |
||
440 | * @param array $record An array with record fields that may affect visibility. |
||
441 | * @return bool True if the record's start time is in the future, FALSE otherwise. |
||
442 | */ |
||
443 | protected function isStartTimeInFuture($table, $record) |
||
454 | |||
455 | /** |
||
456 | * Checks whether a end time field exists for the record's table and if so |
||
457 | * determines if a time is set and whether that time is in the past, |
||
458 | * making the record invisible on the website. |
||
459 | * |
||
460 | * @param string $table The table name. |
||
461 | * @param array $record An array with record fields that may affect visibility. |
||
462 | * @return bool True if the record's end time is in the past, FALSE otherwise. |
||
463 | */ |
||
464 | protected function isEndTimeInPast($table, $record) |
||
475 | |||
476 | /** |
||
477 | * Checks whether the record is in the Index Queue and whether it has been |
||
478 | * indexed already. |
||
479 | * |
||
480 | * @param string $table The table name. |
||
481 | * @param array $record An array with record fields that may affect visibility. |
||
482 | * @return bool True if the record is marked as being indexed |
||
483 | */ |
||
484 | protected function isMarkedAsIndexed($table, $record) |
||
488 | 4 | ||
489 | /** |
||
490 | 4 | * @return Queue |
|
491 | */ |
||
492 | private function getIndexQueue() |
||
496 | |||
497 | /** |
||
498 | * Checks whether the a frontend group field exists for the record and if so |
||
499 | * whether groups have been removed from accessing the record thus making |
||
500 | * the record invisible to at least some people. |
||
501 | * |
||
502 | * @param string $table The table name. |
||
503 | * @param array $record An array with record fields that may affect visibility. |
||
504 | * @return bool TRUE if frontend groups have been removed from access to the record, FALSE otherwise. |
||
505 | */ |
||
506 | protected function hasFrontendGroupsRemoved($table, $record) |
||
525 | |||
526 | /** |
||
527 | * Checks whether the page has been excluded from searching. |
||
528 | * |
||
529 | * @param array $record An array with record fields that may affect visibility. |
||
530 | * @return bool True if the page has been excluded from searching, FALSE otherwise |
||
531 | */ |
||
532 | protected function isPageExcludedFromSearch($record) |
||
536 | |||
537 | /** |
||
538 | * Checks whether a page has a page type that can be indexed. |
||
539 | * Currently standard pages and mount pages can be indexed. |
||
540 | * |
||
541 | * @param array $record A page record |
||
542 | * @return bool TRUE if the page can be indexed according to its page type, FALSE otherwise |
||
543 | */ |
||
544 | protected function isIndexablePageType(array $record) |
||
548 | |||
549 | /** |
||
550 | * Cleans an index from garbage entries. |
||
551 | * |
||
552 | * Was used to clean the index from expired documents/past endtime. Solr 4.8 |
||
553 | * introduced DocExpirationUpdateProcessor to do that job by itself. |
||
554 | * |
||
555 | * The method remains as a dummy for possible later cleanups and to prevent |
||
556 | * things from breaking if others were using it. |
||
557 | * |
||
558 | * @deprecated since 6.0 will be removed in 7.0. deletion is done by DocExpirationUpdateProcessor |
||
559 | * @param Site $site The site to clean indexes on |
||
560 | * @param bool $commitAfterCleanUp Whether to commit right after the clean up, defaults to TRUE |
||
561 | * @return void |
||
562 | */ |
||
563 | public function cleanIndex(Site $site, $commitAfterCleanUp = true) |
||
567 | } |
||
568 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.