Complex classes like PicoDeprecated 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 PicoDeprecated, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 44 | class PicoDeprecated extends AbstractPicoPlugin |
||
| 45 | { |
||
| 46 | /** |
||
| 47 | * This plugin is disabled by default |
||
| 48 | * |
||
| 49 | * @see AbstractPicoPlugin::$enabled |
||
| 50 | */ |
||
| 51 | protected $enabled = false; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The requested file |
||
| 55 | * |
||
| 56 | * @see PicoDeprecated::getRequestFile() |
||
| 57 | * @var string|null |
||
| 58 | */ |
||
| 59 | protected $requestFile; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Enables this plugin on demand and triggers the deprecated event |
||
| 63 | * plugins_loaded() |
||
| 64 | * |
||
| 65 | * @see DummyPlugin::onPluginsLoaded() |
||
| 66 | */ |
||
| 67 | public function onPluginsLoaded(array &$plugins) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Triggers the deprecated event config_loaded($config) |
||
| 96 | * |
||
| 97 | * This method also defines deprecated constants, reads the `config.php` |
||
| 98 | * in Pico's root dir, enables the plugins {@link PicoParsePagesContent} |
||
| 99 | * and {@link PicoExcerpt} and makes `$config` globally accessible (the |
||
| 100 | * latter was removed with Pico 0.9 and was added again as deprecated |
||
| 101 | * feature with Pico 1.0) |
||
| 102 | * |
||
| 103 | * @see PicoDeprecated::defineConstants() |
||
| 104 | * @see PicoDeprecated::loadRootDirConfig() |
||
| 105 | * @see PicoDeprecated::enablePlugins() |
||
| 106 | * @see DummyPlugin::onConfigLoaded() |
||
| 107 | * @param array &$config array of config variables |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | public function onConfigLoaded(array &$config) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Defines deprecated constants |
||
| 122 | * |
||
| 123 | * `ROOT_DIR`, `LIB_DIR`, `PLUGINS_DIR`, `THEMES_DIR` and `CONTENT_EXT` |
||
| 124 | * are deprecated since v1.0, `CONTENT_DIR` existed just in v0.9, |
||
| 125 | * `CONFIG_DIR` just for a short time between v0.9 and v1.0 and |
||
| 126 | * `CACHE_DIR` was dropped with v1.0 without a replacement. |
||
| 127 | * |
||
| 128 | * @see PicoDeprecated::onConfigLoaded() |
||
| 129 | * @return void |
||
| 130 | */ |
||
| 131 | protected function defineConstants() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Read config.php in Pico's root dir |
||
| 159 | * |
||
| 160 | * @see PicoDeprecated::onConfigLoaded() |
||
| 161 | * @see Pico::loadConfig() |
||
| 162 | * @param array &$realConfig array of config variables |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | protected function loadRootDirConfig(array &$realConfig) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Enables the plugins PicoParsePagesContent and PicoExcerpt |
||
| 188 | * |
||
| 189 | * @see PicoParsePagesContent |
||
| 190 | * @see PicoExcerpt |
||
| 191 | * @return void |
||
| 192 | */ |
||
| 193 | protected function enablePlugins() |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Triggers the deprecated event request_url($url) |
||
| 216 | * |
||
| 217 | * @see DummyPlugin::onRequestUrl() |
||
| 218 | */ |
||
| 219 | public function onRequestUrl(&$url) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Sets PicoDeprecated::$requestFile to trigger the deprecated |
||
| 226 | * events after_load_content() and after_404_load_content() |
||
| 227 | * |
||
| 228 | * @see PicoDeprecated::onContentLoaded() |
||
| 229 | * @see PicoDeprecated::on404ContentLoaded() |
||
| 230 | * @see DummyPlugin::onRequestFile() |
||
| 231 | */ |
||
| 232 | public function onRequestFile(&$file) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Triggers the deprecated before_load_content($file) |
||
| 239 | * |
||
| 240 | * @see DummyPlugin::onContentLoading() |
||
| 241 | */ |
||
| 242 | public function onContentLoading(&$file) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Triggers the deprecated event after_load_content($file, $rawContent) |
||
| 249 | * |
||
| 250 | * @see DummyPlugin::onContentLoaded() |
||
| 251 | */ |
||
| 252 | public function onContentLoaded(&$rawContent) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Triggers the deprecated before_404_load_content($file) |
||
| 259 | * |
||
| 260 | * @see DummyPlugin::on404ContentLoading() |
||
| 261 | */ |
||
| 262 | public function on404ContentLoading(&$file) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Triggers the deprecated event after_404_load_content($file, $rawContent) |
||
| 269 | * |
||
| 270 | * @see DummyPlugin::on404ContentLoaded() |
||
| 271 | */ |
||
| 272 | public function on404ContentLoaded(&$rawContent) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Triggers the deprecated event before_read_file_meta($headers) |
||
| 279 | * |
||
| 280 | * @see DummyPlugin::onMetaHeaders() |
||
| 281 | */ |
||
| 282 | public function onMetaHeaders(array &$headers) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Triggers the deprecated event file_meta($meta) |
||
| 289 | * |
||
| 290 | * @see DummyPlugin::onMetaParsed() |
||
| 291 | */ |
||
| 292 | public function onMetaParsed(array &$meta) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Triggers the deprecated event before_parse_content($rawContent) |
||
| 299 | * |
||
| 300 | * @see DummyPlugin::onContentParsing() |
||
| 301 | */ |
||
| 302 | public function onContentParsing(&$rawContent) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Triggers the deprecated events after_parse_content($content) and |
||
| 309 | * content_parsed($content) |
||
| 310 | * |
||
| 311 | * @see DummyPlugin::onContentParsed() |
||
| 312 | */ |
||
| 313 | public function onContentParsed(&$content) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Triggers the deprecated event get_page_data($pages, $meta) |
||
| 323 | * |
||
| 324 | * @see DummyPlugin::onSinglePageLoaded() |
||
| 325 | */ |
||
| 326 | public function onSinglePageLoaded(array &$pageData) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Triggers the deprecated event |
||
| 333 | * get_pages($pages, $currentPage, $previousPage, $nextPage) |
||
| 334 | * |
||
| 335 | * Please note that the `get_pages()` event gets `$pages` passed without a |
||
| 336 | * array index. The index is rebuild later using either the `id` array key |
||
| 337 | * or is derived from the `url` array key. Duplicates are prevented by |
||
| 338 | * adding `~dup` when necessary. |
||
| 339 | * |
||
| 340 | * @see DummyPlugin::onPagesLoaded() |
||
| 341 | */ |
||
| 342 | public function onPagesLoaded( |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Triggers the deprecated event before_twig_register() |
||
| 377 | * |
||
| 378 | * @see DummyPlugin::onTwigRegistration() |
||
| 379 | */ |
||
| 380 | public function onTwigRegistration() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Triggers the deprecated event before_render($twigVariables, $twig, $templateName) |
||
| 387 | * |
||
| 388 | * Please note that the `before_render()` event gets `$templateName` passed |
||
| 389 | * without its file extension. The file extension is later added again. |
||
| 390 | * |
||
| 391 | * @see DummyPlugin::onPageRendering() |
||
| 392 | */ |
||
| 393 | public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Triggers the deprecated event after_render($output) |
||
| 410 | * |
||
| 411 | * @see DummyPlugin::onPageRendered() |
||
| 412 | */ |
||
| 413 | public function onPageRendered(&$output) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Triggers a deprecated event on all plugins |
||
| 420 | * |
||
| 421 | * Deprecated events are also triggered on plugins which implement |
||
| 422 | * {@link PicoPluginInterface}. Please note that the methods are called |
||
| 423 | * directly and not through {@link PicoPluginInterface::handleEvent()}. |
||
| 424 | * |
||
| 425 | * @param string $eventName event to trigger |
||
| 426 | * @param array $params parameters to pass |
||
| 427 | * @return void |
||
| 428 | */ |
||
| 429 | protected function triggerEvent($eventName, array $params = array()) |
||
| 437 | } |
||
| 438 |