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 | /** @var array the types of plugins DokuWiki supports */  | 
            ||
| 14 | const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli'];  | 
            ||
| 15 | |||
| 16 | protected $listByType = [];  | 
            ||
| 17 | /** @var array all installed plugins and their enabled state [plugin=>enabled] */  | 
            ||
| 18 | protected $masterList = [];  | 
            ||
| 19 | protected $pluginCascade = ['default' => [], 'local' => [], 'protected' => []];  | 
            ||
| 20 | protected $lastLocalConfigFile = '';  | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * Populates the master list of plugins  | 
            ||
| 24 | */  | 
            ||
| 25 | public function __construct()  | 
            ||
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * Returns a list of available plugins of given type  | 
            ||
| 33 | *  | 
            ||
| 34 | * @param $type string, plugin_type name;  | 
            ||
| 35 | * the type of plugin to return,  | 
            ||
| 36 | * use empty string for all types  | 
            ||
| 37 | * @param $all bool;  | 
            ||
| 38 | * false to only return enabled plugins,  | 
            ||
| 39 | * true to return both enabled and disabled plugins  | 
            ||
| 40 | *  | 
            ||
| 41 | * @return array of  | 
            ||
| 42 | * - plugin names when $type = ''  | 
            ||
| 43 | * - or plugin component names when a $type is given  | 
            ||
| 44 | *  | 
            ||
| 45 | * @author Andreas Gohr <[email protected]>  | 
            ||
| 46 | */  | 
            ||
| 47 | public function getList($type = '', $all = false)  | 
            ||
| 66 | |||
| 67 | /**  | 
            ||
| 68 | * Loads the given plugin and creates an object of it  | 
            ||
| 69 | *  | 
            ||
| 70 | * @param $type string type of plugin to load  | 
            ||
| 71 | * @param $name string name of the plugin to load  | 
            ||
| 72 | * @param $new bool true to return a new instance of the plugin, false to use an already loaded instance  | 
            ||
| 73 | * @param $disabled bool true to load even disabled plugins  | 
            ||
| 74 | * @return PluginInterface|null the plugin object or null on failure  | 
            ||
| 75 | * @author Andreas Gohr <[email protected]>  | 
            ||
| 76 | *  | 
            ||
| 77 | */  | 
            ||
| 78 | public function load($type, $name, $new = false, $disabled = false)  | 
            ||
| 131 | |||
| 132 | /**  | 
            ||
| 133 | * Whether plugin is disabled  | 
            ||
| 134 | *  | 
            ||
| 135 | * @param string $plugin name of plugin  | 
            ||
| 136 | * @return bool true disabled, false enabled  | 
            ||
| 137 | * @deprecated in favor of the more sensible isEnabled where the return value matches the enabled state  | 
            ||
| 138 | */  | 
            ||
| 139 | public function isDisabled($plugin)  | 
            ||
| 144 | |||
| 145 | /**  | 
            ||
| 146 | * Check whether plugin is disabled  | 
            ||
| 147 | *  | 
            ||
| 148 | * @param string $plugin name of plugin  | 
            ||
| 149 | * @return bool true enabled, false disabled  | 
            ||
| 150 | */  | 
            ||
| 151 | public function isEnabled($plugin)  | 
            ||
| 155 | |||
| 156 | /**  | 
            ||
| 157 | * Disable the plugin  | 
            ||
| 158 | *  | 
            ||
| 159 | * @param string $plugin name of plugin  | 
            ||
| 160 | * @return bool true saving succeed, false saving failed  | 
            ||
| 161 | */  | 
            ||
| 162 | public function disable($plugin)  | 
            ||
| 168 | |||
| 169 | /**  | 
            ||
| 170 | * Enable the plugin  | 
            ||
| 171 | *  | 
            ||
| 172 | * @param string $plugin name of plugin  | 
            ||
| 173 | * @return bool true saving succeed, false saving failed  | 
            ||
| 174 | */  | 
            ||
| 175 | public function enable($plugin)  | 
            ||
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * Returns cascade of the config files  | 
            ||
| 184 | *  | 
            ||
| 185 | * @return array with arrays of plugin configs  | 
            ||
| 186 | */  | 
            ||
| 187 | public function getCascade()  | 
            ||
| 191 | |||
| 192 | /**  | 
            ||
| 193 | * Read all installed plugins and their current enabled state  | 
            ||
| 194 | */  | 
            ||
| 195 | protected function populateMasterList()  | 
            ||
| 218 | |||
| 219 | /**  | 
            ||
| 220 | * Includes the plugin config $files  | 
            ||
| 221 | * and returns the entries of the $plugins array set in these files  | 
            ||
| 222 | *  | 
            ||
| 223 | * @param array $files list of files to include, latter overrides previous  | 
            ||
| 224 | * @return array with entries of the $plugins arrays of the included files  | 
            ||
| 225 | */  | 
            ||
| 226 | protected function checkRequire($files)  | 
            ||
| 236 | |||
| 237 | /**  | 
            ||
| 238 | * Save the current list of plugins  | 
            ||
| 239 | *  | 
            ||
| 240 | * @param bool $forceSave ;  | 
            ||
| 241 | * false to save only when config changed  | 
            ||
| 242 | * true to always save  | 
            ||
| 243 | * @return bool true saving succeed, false saving failed  | 
            ||
| 244 | */  | 
            ||
| 245 | protected function saveList($forceSave = false)  | 
            ||
| 275 | |||
| 276 | /**  | 
            ||
| 277 | * Rebuild the set of local plugins  | 
            ||
| 278 | *  | 
            ||
| 279 | * @return array array of plugins to be saved in end($config_cascade['plugins']['local'])  | 
            ||
| 280 | */  | 
            ||
| 281 | protected function rebuildLocal()  | 
            ||
| 297 | |||
| 298 | /**  | 
            ||
| 299 | * Build the list of plugins and cascade  | 
            ||
| 300 | *  | 
            ||
| 301 | */  | 
            ||
| 302 | protected function loadConfig()  | 
            ||
| 325 | |||
| 326 | /**  | 
            ||
| 327 | * Returns a list of available plugin components of given type  | 
            ||
| 328 | *  | 
            ||
| 329 | * @param string $type plugin_type name; the type of plugin to return,  | 
            ||
| 330 | * @param bool $enabled true to return enabled plugins,  | 
            ||
| 331 | * false to return disabled plugins  | 
            ||
| 332 | * @return array of plugin components of requested type  | 
            ||
| 333 | */  | 
            ||
| 334 | protected function getListByType($type, $enabled)  | 
            ||
| 365 | |||
| 366 | /**  | 
            ||
| 367 | * Split name in a plugin name and a component name  | 
            ||
| 368 | *  | 
            ||
| 369 | * @param string $name  | 
            ||
| 370 | * @return array with  | 
            ||
| 371 | * - plugin name  | 
            ||
| 372 | * - and component name when available, otherwise empty string  | 
            ||
| 373 | */  | 
            ||
| 374 | protected function splitName($name)  | 
            ||
| 382 | |||
| 383 | /**  | 
            ||
| 384 | * Returns inverse boolean value of the input  | 
            ||
| 385 | *  | 
            ||
| 386 | * @param mixed $input  | 
            ||
| 387 | * @return bool inversed boolean value of input  | 
            ||
| 388 | */  | 
            ||
| 389 | protected function negate($input)  | 
            ||
| 393 | }  | 
            ||
| 394 |