Complex classes like Index 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 Index, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Index { |
||
| 29 | use |
||
| 30 | Singleton, |
||
| 31 | Router; |
||
| 32 | |||
| 33 | protected $request_method; |
||
| 34 | protected $working_directory = ''; |
||
| 35 | protected $called_once = false; |
||
| 36 | /** |
||
| 37 | * Reference to Request::instance()->route_path |
||
| 38 | * |
||
| 39 | * @var string[] |
||
| 40 | */ |
||
| 41 | protected $path; |
||
| 42 | /** |
||
| 43 | * Reference to Request::instance()->route_ids |
||
| 44 | * |
||
| 45 | * @var int[] |
||
| 46 | */ |
||
| 47 | protected $ids; |
||
| 48 | /** |
||
| 49 | * Path that will be used by controller to render page |
||
| 50 | * |
||
| 51 | * @var string[] |
||
| 52 | */ |
||
| 53 | protected $controller_path = ['index']; |
||
| 54 | /** |
||
| 55 | * Detecting module folder including of admin/api request type, including prepare file, including of plugins |
||
| 56 | * |
||
| 57 | * @throws ExitException |
||
| 58 | */ |
||
| 59 | function construct () { |
||
| 107 | /** |
||
| 108 | * Check if visitor is allowed to make current request to closed site |
||
| 109 | * |
||
| 110 | * @param Request $Request |
||
| 111 | * |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | protected function allow_closed_site_request ($Request) { |
||
| 123 | /** |
||
| 124 | * Check whether user allowed to access to specified label |
||
| 125 | * |
||
| 126 | * @param string $label |
||
| 127 | * |
||
| 128 | * @return bool |
||
| 129 | */ |
||
| 130 | protected function check_permission ($label) { |
||
| 140 | /** |
||
| 141 | * Page generation, blocks processing, adding of form with save/apply/cancel/reset and/or custom users buttons |
||
| 142 | * |
||
| 143 | * @throws ExitException |
||
| 144 | */ |
||
| 145 | protected function render_page () { |
||
| 152 | /** |
||
| 153 | * Render page title |
||
| 154 | */ |
||
| 155 | protected function render_title () { |
||
| 171 | /** |
||
| 172 | * Render page content (without blocks, just module content) |
||
| 173 | * |
||
| 174 | * @throws ExitException |
||
| 175 | */ |
||
| 176 | protected function render_content () { |
||
| 189 | /** |
||
| 190 | * Blocks rendering |
||
| 191 | */ |
||
| 192 | protected function render_blocks () { |
||
| 275 | /** |
||
| 276 | * Check whether to render block or not based on its properties (active state, when start to show, when it expires and permissions) |
||
| 277 | * |
||
| 278 | * @param array $block |
||
| 279 | * |
||
| 280 | * @return bool |
||
| 281 | */ |
||
| 282 | protected function should_block_be_rendered ($block) { |
||
| 292 | /** |
||
| 293 | * @param string $text |
||
| 294 | * |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | protected function ml_process ($text) { |
||
| 300 | /** |
||
| 301 | * Getter for `controller_path` property (no other properties supported currently) |
||
| 302 | * |
||
| 303 | * @param string $property |
||
| 304 | * |
||
| 305 | * @return false|string[] |
||
| 306 | */ |
||
| 307 | function __get ($property) { |
||
| 314 | /** |
||
| 315 | * Executes plugins processing, blocks and module page generation |
||
| 316 | * |
||
| 317 | * @throws ExitException |
||
| 318 | */ |
||
| 319 | function __finish () { |
||
| 331 | } |
||
| 332 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: