Complex classes like Util 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 Util, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
49 | class Util |
||
50 | { |
||
51 | |||
52 | /** |
||
53 | * Generates a document id for documents representing page records. |
||
54 | * |
||
55 | * @param int $uid The page's uid |
||
56 | * @param int $typeNum The page's typeNum |
||
57 | * @param int $language the language id, defaults to 0 |
||
58 | * @param string $accessGroups comma separated list of uids of groups that have access to that page |
||
59 | * @param string $mountPointParameter The mount point parameter that is used to access the page. |
||
60 | * @return string The document id for that page |
||
61 | */ |
||
62 | 54 | public static function getPageDocumentId($uid, $typeNum = 0, $language = 0, $accessGroups = '0,-1', $mountPointParameter = '') |
|
74 | |||
75 | 54 | /** |
|
76 | 54 | * Generates a document id in the form $siteHash/$type/$uid. |
|
77 | * |
||
78 | * @param string $table The records table name |
||
79 | * @param int $rootPageId The record's site root id |
||
80 | * @param int $uid The record's uid |
||
81 | * @param string $additionalIdParameters Additional ID parameters |
||
82 | 54 | * @return string A document id |
|
83 | */ |
||
84 | public static function getDocumentId($table, $rootPageId, $uid, $additionalIdParameters = '') |
||
97 | |||
98 | /** |
||
99 | * Shortcut to retrieve the TypoScript configuration for EXT:solr |
||
100 | 70 | * (plugin.tx_solr) from TSFE. |
|
101 | 70 | * |
|
102 | 70 | * @return TypoScriptConfiguration |
|
103 | */ |
||
104 | 70 | public static function getSolrConfiguration() |
|
109 | 70 | ||
110 | /** |
||
111 | * Gets the Solr configuration for a specific root page id. |
||
112 | * To be used from the backend. |
||
113 | * |
||
114 | * @param int $pageId Id of the (root) page to get the Solr configuration from. |
||
115 | * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
||
116 | * @param int $language System language uid, optional, defaults to 0 |
||
117 | * @return TypoScriptConfiguration The Solr configuration for the requested tree. |
||
118 | */ |
||
119 | public static function getSolrConfigurationFromPageId($pageId, $initializeTsfe = false, $language = 0) |
||
124 | |||
125 | /** |
||
126 | * Loads the TypoScript configuration for a given page id and language. |
||
127 | * Language usage may be disabled to get the default TypoScript |
||
128 | * configuration. |
||
129 | * |
||
130 | * @param int $pageId Id of the (root) page to get the Solr configuration from. |
||
131 | * @param string $path The TypoScript configuration path to retrieve. |
||
132 | * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
||
133 | * @param int $language System language uid, optional, defaults to 0 |
||
134 | * @param bool $useTwoLevelCache Flag to enable the two level cache for the typoscript configuration array |
||
135 | * @return TypoScriptConfiguration The Solr configuration for the requested tree. |
||
136 | */ |
||
137 | public static function getConfigurationFromPageId($pageId, $path, $initializeTsfe = false, $language = 0, $useTwoLevelCache = true) |
||
174 | |||
175 | /** |
||
176 | * This method retrieves the closest pageId where a configuration is located, when this |
||
177 | * feature is enabled. |
||
178 | * |
||
179 | * @param int $pageId |
||
180 | * @return int |
||
181 | */ |
||
182 | protected static function getConfigurationPageIdToUse($pageId) |
||
193 | |||
194 | /** |
||
195 | * Initializes a TSFE, if required and builds an configuration array, containing the solr configuration. |
||
196 | * |
||
197 | * @param integer $pageId |
||
198 | * @param string $path |
||
199 | * @param boolean $initializeTsfe |
||
200 | * @param integer $language |
||
201 | * @return array |
||
202 | */ |
||
203 | protected static function buildConfigurationArray($pageId, $path, $initializeTsfe, $language) |
||
214 | |||
215 | 74 | /** |
|
216 | 74 | * Builds the configuration object from a config array and returns it. |
|
217 | 74 | * |
|
218 | 65 | * @param array $configurationToUse |
|
219 | * @param int $pageId |
||
220 | * @param int $languageId |
||
221 | * @param string $typoScriptPath |
||
222 | * @return TypoScriptConfiguration |
||
223 | */ |
||
224 | 74 | protected static function buildTypoScriptConfigurationFromArray(array $configurationToUse, $pageId, $languageId, $typoScriptPath) |
|
229 | |||
230 | 73 | /** |
|
231 | 73 | * This function is used to retrieve the configuration from a previous initialized TSFE |
|
232 | * (see: getConfigurationFromPageId) |
||
233 | * |
||
234 | 73 | * @param string $path |
|
235 | * @return mixed |
||
236 | */ |
||
237 | private static function getConfigurationFromInitializedTSFE($path) |
||
245 | |||
246 | 73 | /** |
|
247 | * This function is used to retrieve the configuration from an existing TSFE instance |
||
248 | * @param $pageId |
||
249 | * @param $path |
||
250 | * @param $language |
||
251 | * @return mixed |
||
252 | */ |
||
253 | private static function getConfigurationFromExistingTSFE($pageId, $path, $language) |
||
297 | |||
298 | 74 | /** |
|
299 | * Initializes the TSFE for a given page ID and language. |
||
300 | 74 | * |
|
301 | 74 | * @param int $pageId The page id to initialize the TSFE for |
|
302 | * @param int $language System language uid, optional, defaults to 0 |
||
303 | * @param bool $useCache Use cache to reuse TSFE |
||
304 | * @return void |
||
305 | */ |
||
306 | public static function initializeTsfe($pageId, $language = 0, $useCache = true) |
||
368 | |||
369 | 73 | /** |
|
370 | * Check if record ($table, $uid) is a workspace record |
||
371 | * |
||
372 | * @param string $table The table the record belongs to |
||
373 | * @param int $uid The record's uid |
||
374 | * @return bool TRUE if the record is in a draft workspace, FALSE if it's a LIVE record |
||
375 | */ |
||
376 | public static function isDraftRecord($table, $uid) |
||
390 | 21 | ||
391 | /** |
||
392 | 21 | * Checks whether a record is a localization overlay. |
|
393 | 21 | * |
|
394 | * @param string $tableName The record's table name |
||
395 | * @param array $record The record to check |
||
396 | 21 | * @return bool TRUE if the record is a language overlay, FALSE otherwise |
|
397 | 21 | */ |
|
398 | public static function isLocalizedRecord($tableName, array $record) |
||
412 | |||
413 | 21 | /** |
|
414 | * Check if the page type of a page record is allowed |
||
415 | 21 | * |
|
416 | 21 | * @param array $pageRecord The pages database row |
|
417 | 21 | * @param string $configurationName The name of the configuration to use. |
|
418 | 21 | * |
|
419 | * @return bool TRUE if the page type is allowed, otherwise FALSE |
||
420 | */ |
||
421 | 21 | public static function isAllowedPageType(array $pageRecord, $configurationName = 'pages') |
|
433 | 21 | ||
434 | /** |
||
435 | 21 | * Get allowed page types |
|
436 | 21 | * |
|
437 | * @param int $pageId Page ID |
||
438 | * @param string $configurationName The name of the configuration to use. |
||
439 | * |
||
440 | 21 | * @return array Allowed page types to compare to a doktype of a page record |
|
441 | 21 | */ |
|
442 | 21 | public static function getAllowedPageTypes($pageId, $configurationName = 'pages') |
|
448 | |||
449 | /** |
||
450 | * Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix |
||
451 | * is set to "auto". |
||
452 | * |
||
453 | 39 | * @param TypoScriptFrontendController $TSFE |
|
454 | * @return string |
||
455 | 39 | */ |
|
456 | public static function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE) |
||
470 | |||
471 | /** |
||
472 | * This function can be used to check if one of the strings in needles is |
||
473 | * contained in the haystack. |
||
474 | * |
||
475 | 32 | * |
|
476 | * Example: |
||
477 | 32 | * |
|
478 | * haystack: the brown fox |
||
479 | 32 | * needles: ['hello', 'world'] |
|
480 | 7 | * result: false |
|
481 | * |
||
482 | 7 | * haystack: the brown fox |
|
483 | 3 | * needles: ['is', 'fox'] |
|
484 | * result: true |
||
485 | * |
||
486 | * @param string $haystack |
||
487 | 32 | * @param array $needles |
|
488 | * @return bool |
||
489 | */ |
||
490 | public static function containsOneOfTheStrings($haystack, array $needles) |
||
501 | } |
||
502 |