Complex classes like PluginController 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 PluginController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class PluginController |
||
12 | { |
||
13 | |||
14 | protected $list_bytype = array(); |
||
15 | protected $tmp_plugins = array(); |
||
16 | protected $plugin_cascade = array('default' => array(), 'local' => array(), 'protected' => array()); |
||
17 | protected $last_local_config_file = ''; |
||
18 | |||
19 | /** |
||
20 | * Populates the master list of plugins |
||
21 | */ |
||
22 | public function __construct() |
||
27 | |||
28 | /** |
||
29 | * Returns a list of available plugins of given type |
||
30 | * |
||
31 | * @param $type string, plugin_type name; |
||
32 | * the type of plugin to return, |
||
33 | * use empty string for all types |
||
34 | * @param $all bool; |
||
35 | * false to only return enabled plugins, |
||
36 | * true to return both enabled and disabled plugins |
||
37 | * |
||
38 | * @return array of |
||
39 | * - plugin names when $type = '' |
||
40 | * - or plugin component names when a $type is given |
||
41 | * |
||
42 | * @author Andreas Gohr <[email protected]> |
||
43 | */ |
||
44 | public function getList($type = '', $all = false) |
||
63 | |||
64 | /** |
||
65 | * Loads the given plugin and creates an object of it |
||
66 | * |
||
67 | * @author Andreas Gohr <[email protected]> |
||
68 | * |
||
69 | * @param $type string type of plugin to load |
||
70 | * @param $name string name of the plugin to load |
||
71 | * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance |
||
72 | * @param $disabled bool true to load even disabled plugins |
||
73 | * @return PluginInterface|null the plugin object or null on failure |
||
74 | */ |
||
75 | public function load($type, $name, $new = false, $disabled = false) |
||
128 | |||
129 | /** |
||
130 | * Whether plugin is disabled |
||
131 | * |
||
132 | * @param string $plugin name of plugin |
||
133 | * @return bool true disabled, false enabled |
||
134 | * @deprecated in favor of the more sensible isEnabled where the return value matches the enabled state |
||
135 | */ |
||
136 | public function isDisabled($plugin) |
||
141 | |||
142 | /** |
||
143 | * Check whether plugin is disabled |
||
144 | * |
||
145 | * @param string $plugin name of plugin |
||
146 | * @return bool true enabled, false disabled |
||
147 | */ |
||
148 | public function isEnabled($plugin) |
||
152 | |||
153 | /** |
||
154 | * Disable the plugin |
||
155 | * |
||
156 | * @param string $plugin name of plugin |
||
157 | * @return bool true saving succeed, false saving failed |
||
158 | */ |
||
159 | public function disable($plugin) |
||
165 | |||
166 | /** |
||
167 | * Enable the plugin |
||
168 | * |
||
169 | * @param string $plugin name of plugin |
||
170 | * @return bool true saving succeed, false saving failed |
||
171 | */ |
||
172 | public function enable($plugin) |
||
178 | |||
179 | /** |
||
180 | * Returns cascade of the config files |
||
181 | * |
||
182 | * @return array with arrays of plugin configs |
||
183 | */ |
||
184 | public function getCascade() |
||
188 | |||
189 | protected function _populateMasterList() |
||
214 | |||
215 | /** |
||
216 | * Includes the plugin config $files |
||
217 | * and returns the entries of the $plugins array set in these files |
||
218 | * |
||
219 | * @param array $files list of files to include, latter overrides previous |
||
220 | * @return array with entries of the $plugins arrays of the included files |
||
221 | */ |
||
222 | protected function checkRequire($files) |
||
232 | |||
233 | /** |
||
234 | * Save the current list of plugins |
||
235 | * |
||
236 | * @param bool $forceSave ; |
||
237 | * false to save only when config changed |
||
238 | * true to always save |
||
239 | * @return bool true saving succeed, false saving failed |
||
240 | */ |
||
241 | protected function saveList($forceSave = false) |
||
271 | |||
272 | /** |
||
273 | * Rebuild the set of local plugins |
||
274 | * |
||
275 | * @return array array of plugins to be saved in end($config_cascade['plugins']['local']) |
||
276 | */ |
||
277 | protected function rebuildLocal() |
||
293 | |||
294 | /** |
||
295 | * Build the list of plugins and cascade |
||
296 | * |
||
297 | */ |
||
298 | protected function loadConfig() |
||
321 | |||
322 | /** |
||
323 | * Returns a list of available plugin components of given type |
||
324 | * |
||
325 | * @param string $type plugin_type name; the type of plugin to return, |
||
326 | * @param bool $enabled true to return enabled plugins, |
||
327 | * false to return disabled plugins |
||
328 | * @return array of plugin components of requested type |
||
329 | */ |
||
330 | protected function _getListByType($type, $enabled) |
||
361 | |||
362 | /** |
||
363 | * Split name in a plugin name and a component name |
||
364 | * |
||
365 | * @param string $name |
||
366 | * @return array with |
||
367 | * - plugin name |
||
368 | * - and component name when available, otherwise empty string |
||
369 | */ |
||
370 | protected function _splitName($name) |
||
378 | |||
379 | /** |
||
380 | * Returns inverse boolean value of the input |
||
381 | * |
||
382 | * @param mixed $input |
||
383 | * @return bool inversed boolean value of input |
||
384 | */ |
||
385 | protected function negate($input) |
||
389 | } |
||
390 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.