Complex classes like App 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 App, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class App { |
||
| 34 | use |
||
| 35 | Singleton, |
||
| 36 | Router, |
||
| 37 | Static_files; |
||
| 38 | const INIT_STATE_METHOD = 'init'; |
||
| 39 | protected function init () { |
||
| 42 | /** |
||
| 43 | * Executes blocks and module page generation |
||
| 44 | * |
||
| 45 | * @throws ExitException |
||
| 46 | */ |
||
| 47 | function execute () { |
||
| 68 | /** |
||
| 69 | * @param bool $closed_site |
||
| 70 | * @param Request $Request |
||
| 71 | * |
||
| 72 | * @throws ExitException |
||
| 73 | */ |
||
| 74 | protected function handle_closed_site ($closed_site, $Request) { |
||
| 95 | /** |
||
| 96 | * Check if visitor is allowed to make current request to closed site |
||
| 97 | * |
||
| 98 | * @param Request $Request |
||
| 99 | * |
||
| 100 | * @return bool |
||
| 101 | */ |
||
| 102 | protected function allow_closed_site_request ($Request) { |
||
| 112 | /** |
||
| 113 | * Check whether user allowed to access to specified label |
||
| 114 | * |
||
| 115 | * @param Request $Request |
||
| 116 | * @param string $label |
||
| 117 | * |
||
| 118 | * @return bool |
||
| 119 | */ |
||
| 120 | protected function check_permission ($Request, $label) { |
||
| 132 | /** |
||
| 133 | * @param Request $Request |
||
| 134 | * |
||
| 135 | * @throws ExitException |
||
| 136 | */ |
||
| 137 | protected function render ($Request) { |
||
| 147 | /** |
||
| 148 | * Render page title |
||
| 149 | * |
||
| 150 | * @param Request $Request |
||
| 151 | * @param Page $Page |
||
| 152 | */ |
||
| 153 | protected function render_title ($Request, $Page) { |
||
| 165 | /** |
||
| 166 | * Blocks rendering |
||
| 167 | * |
||
| 168 | * @param Page $Page |
||
| 169 | */ |
||
| 170 | protected function render_blocks ($Page) { |
||
| 238 | /** |
||
| 239 | * Check whether to render block or not based on its properties (active state, when start to show, when it expires and permissions) |
||
| 240 | * |
||
| 241 | * @param array $block |
||
| 242 | * |
||
| 243 | * @return bool |
||
| 244 | */ |
||
| 245 | protected function should_block_be_rendered ($block) { |
||
| 255 | /** |
||
| 256 | * @param string $text |
||
| 257 | * |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | protected function ml_process ($text) { |
||
| 263 | /** |
||
| 264 | * Getter for `controller_path` property (no other properties supported currently) |
||
| 265 | * |
||
| 266 | * @param string $property |
||
| 267 | * |
||
| 268 | * @return false|string[] |
||
| 269 | */ |
||
| 270 | function __get ($property) { |
||
| 276 | } |
||
| 277 |