Complex classes like Doku_Plugin_Controller 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 Doku_Plugin_Controller, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Doku_Plugin_Controller { |
||
| 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() { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Returns a list of available plugins of given type |
||
| 29 | * |
||
| 30 | * @param $type string, plugin_type name; |
||
| 31 | * the type of plugin to return, |
||
| 32 | * use empty string for all types |
||
| 33 | * @param $all bool; |
||
| 34 | * false to only return enabled plugins, |
||
| 35 | * true to return both enabled and disabled plugins |
||
| 36 | * |
||
| 37 | * @return array of |
||
| 38 | * - plugin names when $type = '' |
||
| 39 | * - or plugin component names when a $type is given |
||
| 40 | * |
||
| 41 | * @author Andreas Gohr <[email protected]> |
||
| 42 | */ |
||
| 43 | public function getList($type='',$all=false){ |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Loads the given plugin and creates an object of it |
||
| 64 | * |
||
| 65 | * @author Andreas Gohr <[email protected]> |
||
| 66 | * |
||
| 67 | * @param $type string type of plugin to load |
||
| 68 | * @param $name string name of the plugin to load |
||
| 69 | * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance |
||
| 70 | * @param $disabled bool true to load even disabled plugins |
||
| 71 | * @return DokuWiki_PluginInterface|null the plugin object or null on failure |
||
| 72 | */ |
||
| 73 | public function load($type,$name,$new=false,$disabled=false){ |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Whether plugin is disabled |
||
| 129 | * |
||
| 130 | * @param string $plugin name of plugin |
||
| 131 | * @return bool true disabled, false enabled |
||
| 132 | */ |
||
| 133 | public function isdisabled($plugin) { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Disable the plugin |
||
| 139 | * |
||
| 140 | * @param string $plugin name of plugin |
||
| 141 | * @return bool true saving succeed, false saving failed |
||
| 142 | */ |
||
| 143 | public function disable($plugin) { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Enable the plugin |
||
| 151 | * |
||
| 152 | * @param string $plugin name of plugin |
||
| 153 | * @return bool true saving succeed, false saving failed |
||
| 154 | */ |
||
| 155 | public function enable($plugin) { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Returns directory name of plugin |
||
| 163 | * |
||
| 164 | * @param string $plugin name of plugin |
||
| 165 | * @return string name of directory |
||
| 166 | */ |
||
| 167 | public function get_directory($plugin) { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Returns cascade of the config files |
||
| 173 | * |
||
| 174 | * @return array with arrays of plugin configs |
||
| 175 | */ |
||
| 176 | public function getCascade() { |
||
| 179 | |||
| 180 | protected function _populateMasterList() { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Includes the plugin config $files |
||
| 207 | * and returns the entries of the $plugins array set in these files |
||
| 208 | * |
||
| 209 | * @param array $files list of files to include, latter overrides previous |
||
| 210 | * @return array with entries of the $plugins arrays of the included files |
||
| 211 | */ |
||
| 212 | protected function checkRequire($files) { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Save the current list of plugins |
||
| 224 | * |
||
| 225 | * @param bool $forceSave; |
||
|
|
|||
| 226 | * false to save only when config changed |
||
| 227 | * true to always save |
||
| 228 | * @return bool true saving succeed, false saving failed |
||
| 229 | */ |
||
| 230 | protected function saveList($forceSave = false) { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Rebuild the set of local plugins |
||
| 262 | * |
||
| 263 | * @return array array of plugins to be saved in end($config_cascade['plugins']['local']) |
||
| 264 | */ |
||
| 265 | protected function rebuildLocal() { |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Build the list of plugins and cascade |
||
| 283 | * |
||
| 284 | */ |
||
| 285 | protected function loadConfig() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Returns a list of available plugin components of given type |
||
| 309 | * |
||
| 310 | * @param string $type plugin_type name; the type of plugin to return, |
||
| 311 | * @param bool $enabled true to return enabled plugins, |
||
| 312 | * false to return disabled plugins |
||
| 313 | * @return array of plugin components of requested type |
||
| 314 | */ |
||
| 315 | protected function _getListByType($type, $enabled) { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Split name in a plugin name and a component name |
||
| 349 | * |
||
| 350 | * @param string $name |
||
| 351 | * @return array with |
||
| 352 | * - plugin name |
||
| 353 | * - and component name when available, otherwise empty string |
||
| 354 | */ |
||
| 355 | protected function _splitName($name) { |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Returns inverse boolean value of the input |
||
| 365 | * |
||
| 366 | * @param mixed $input |
||
| 367 | * @return bool inversed boolean value of input |
||
| 368 | */ |
||
| 369 | protected function negate($input) { |
||
| 372 | } |
||
| 373 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.