Complex classes like Core 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 Core, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | $whoops = new \Whoops\Run; |
||
27 | $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); |
||
|
|||
28 | $whoops->register(); |
||
29 | |||
30 | // Fire core creation event |
||
31 | Event::fire('core.created', array(&$this)); |
||
32 | |||
33 | // Signal core configure event |
||
34 | Event::signal('core.configure', array($this->system_path . __SAMSON_CONFIG_PATH)); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Change current system working environment or receive |
||
39 | * current system enviroment if no arguments are passed. |
||
40 | * |
||
41 | * @param string $environment Environment identifier |
||
42 | * |
||
43 | * TODO: Function has two different logics - needs to be changed! |
||
44 | * @return $this|string Chaining or current system environment |
||
45 | */ |
||
46 | public function environment($environment = Scheme::BASE) |
||
58 | |||
59 | /** |
||
60 | * Start SamsonPHP framework. |
||
61 | * |
||
62 | * @param string $default Default module identifier |
||
63 | * |
||
64 | * @throws ViewPathNotFound |
||
65 | */ |
||
66 | public function start($default) |
||
106 | } |
||
107 |
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: