Complex classes like Popup 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 Popup, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class Popup |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * cObj for the RTE replacement |
||
45 | * |
||
46 | * @var ContentObjectRenderer |
||
47 | */ |
||
48 | public $cObj; |
||
49 | |||
50 | /** |
||
51 | * init the convert functions |
||
52 | */ |
||
53 | protected $convertParams = []; |
||
54 | |||
55 | /** |
||
56 | * Possible popup parameter |
||
57 | */ |
||
58 | public $allowedParams = [ |
||
59 | 'height' => 'integer', |
||
60 | 'width' => 'integer', |
||
61 | 'resizable' => 'boolean', |
||
62 | 'scrollbars' => 'boolean', |
||
63 | 'menubar' => 'boolean', |
||
64 | 'status' => 'boolean', |
||
65 | 'location' => 'boolean', |
||
66 | 'toolbar' => 'boolean', |
||
67 | 'dependent' => 'boolean', |
||
68 | 'top' => 'integer', |
||
69 | 'left' => 'integer', |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * Possible popup parameter |
||
74 | */ |
||
75 | public $advancedParams = [ |
||
76 | 'once_per_session' => 'boolean', |
||
77 | 'once_per_link' => 'boolean', |
||
78 | 'center' => 'boolean', |
||
79 | 'maximize' => 'boolean', |
||
80 | 'popunder' => 'boolean', |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * Static Funktion for hooking the menu link generation |
||
85 | * |
||
86 | * @param array|int $pageOrPageID The Page row or the page ID |
||
87 | * @param array $LD A reference of the Link Data |
||
88 | */ |
||
89 | public static function makeMenuLink($pageOrPageID, &$LD) |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Get the target of a page |
||
100 | * |
||
101 | * @param array|integer $pageOrPageID The Page row or the page ID |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getPopupTarget($pageOrPageID) |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Return the default configuration |
||
132 | * |
||
133 | * @param $page |
||
134 | * @param bool $advanced |
||
135 | * |
||
136 | * @return array The default configuration |
||
137 | */ |
||
138 | public function getDefaultConfiguration($page, $advanced = false) |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Text parser for internal popup links |
||
156 | * |
||
157 | * @author Tim Lochmueller |
||
158 | * @author before 2009 Mathias Schreiber, Rene Fritz |
||
159 | */ |
||
160 | public function textParse($content, $conf) |
||
234 | |||
235 | |||
236 | /** |
||
237 | * Merges two arrays recursively, overruling the values of the first array |
||
238 | * in case of identical keys, ie. keeping the values of the second. |
||
239 | */ |
||
240 | public function arrayMergeRecursiveOverrule($arr0, $arr1, $notAddKeys = 0) |
||
261 | |||
262 | |||
263 | /** |
||
264 | * Load TypoScript for the backend |
||
265 | * This is important for the single configuration concept in the popup extension |
||
266 | */ |
||
267 | public function loadTypoScript($pid, $pluginExtKey = 'tx_popup_pi1') |
||
279 | |||
280 | |||
281 | /** |
||
282 | * Start the convertion prcess |
||
283 | * Init this process mit the parameter for the convertion |
||
284 | * all iligal parameter will be removed |
||
285 | */ |
||
286 | public function convertInit($params) |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Convert a TYPO3 Popup configuration String to an Array |
||
294 | * |
||
295 | * @param string $configString The T3 configuration string (Like "width:height:param1=value,param2=value2") |
||
296 | * @param boolean $advanced If set, the advanced parameter will be included in the array |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function convertCfg2Array($configString, $advanced = false) |
||
319 | |||
320 | |||
321 | /** |
||
322 | * Convert JavaScript Params to an array |
||
323 | * |
||
324 | * @param string $string |
||
325 | * @param string $params Javascript param String (Like "param1=value,param2=value2") |
||
326 | * |
||
327 | * @return array |
||
328 | */ |
||
329 | 1 | public function convertJs2Array($string, $params) |
|
346 | |||
347 | |||
348 | /** |
||
349 | * Convert an array to a TYPO3 Popup configuration String |
||
350 | * |
||
351 | * @param array $array Data Array of the field (key value pairs) |
||
352 | * @param boolean $advanced If set, the advanced parameter will be included in the array |
||
353 | * |
||
354 | * @return string |
||
355 | */ |
||
356 | public function convertArray2Cfg($array, $advanced = false) |
||
386 | |||
387 | |||
388 | /** |
||
389 | * Convert an array to a JS configuration String |
||
390 | */ |
||
391 | public function convertArray2Js($array) |
||
412 | |||
413 | |||
414 | /** |
||
415 | * Convert a TYPO3 Popup configuration String to a JS configuration String |
||
416 | */ |
||
417 | public function convertCfg2Js($string) |
||
421 | |||
422 | |||
423 | /** |
||
424 | * Convert a JS configuration string to a TYPO3 Popup configuration |
||
425 | */ |
||
426 | public function convertJs2Cfg($string) |
||
430 | |||
431 | |||
432 | /** |
||
433 | * Set all fields in the given configuration by the param parameter |
||
434 | */ |
||
435 | protected function setAllFields($params, $config) |
||
452 | } |
||
453 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.