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 |
||
34 | class App { |
||
35 | use |
||
36 | Singleton, |
||
37 | Router; |
||
38 | const INIT_STATE_METHOD = 'init'; |
||
39 | protected function init () { |
||
42 | /** |
||
43 | * Executes plugins processing, blocks and module page generation |
||
44 | * |
||
45 | * @throws ExitException |
||
46 | */ |
||
47 | function execute () { |
||
69 | /** |
||
70 | * @param bool $closed_site |
||
71 | * @param Request $Request |
||
72 | * |
||
73 | * @throws ExitException |
||
74 | */ |
||
75 | protected function handle_closed_site ($closed_site, $Request) { |
||
96 | /** |
||
97 | * Check if visitor is allowed to make current request to closed site |
||
98 | * |
||
99 | * @param Request $Request |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | 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) { |
||
259 | /** |
||
260 | * Check whether to render block or not based on its properties (active state, when start to show, when it expires and permissions) |
||
261 | * |
||
262 | * @param array $block |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | protected function should_block_be_rendered ($block) { |
||
276 | /** |
||
277 | * @param string $text |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | protected function ml_process ($text) { |
||
284 | /** |
||
285 | * Getter for `controller_path` property (no other properties supported currently) |
||
286 | * |
||
287 | * @param string $property |
||
288 | * |
||
289 | * @return false|string[] |
||
290 | */ |
||
291 | function __get ($property) { |
||
297 | } |
||
298 |