Complex classes like Micro 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 Micro, and based on these observations, apply Extract Interface, too.
1 | <?php /** Micro */ |
||
32 | class Micro |
||
33 | { |
||
34 | /** @const string VERSION Version framework */ |
||
35 | const VERSION = '1.1'; |
||
36 | |||
37 | /** @var IContainer $container Container is a container for components and options */ |
||
38 | protected $container; |
||
39 | /** @var string $appDir */ |
||
40 | protected $appDir; |
||
41 | |||
42 | /** @var bool $loaded Micro loaded flag */ |
||
43 | private $loaded; |
||
44 | /** @var bool $debug Debug-mode flag */ |
||
45 | private $debug = true; |
||
46 | /** @var string $environment Application environment */ |
||
47 | private $environment = 'devel'; |
||
48 | /** @var float $startTime Time of start framework */ |
||
49 | private $startTime; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Initialize application |
||
54 | * |
||
55 | * @access public |
||
56 | * |
||
57 | * @param string $environment Application environment: devel , production , test, other |
||
58 | * @param bool $debug Debug-mode flag |
||
59 | * |
||
60 | * @result void |
||
61 | */ |
||
62 | public function __construct($environment = 'devel', $debug = true) |
||
76 | |||
77 | /** |
||
78 | * Clone application |
||
79 | * |
||
80 | * @access public |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | public function __clone() |
||
93 | |||
94 | /** |
||
95 | * Running application |
||
96 | * |
||
97 | * @access public |
||
98 | * |
||
99 | * @param IRequest $request Request object |
||
100 | * |
||
101 | * @return Response |
||
102 | * @throws \Exception |
||
103 | */ |
||
104 | public function run(IRequest $request) |
||
117 | |||
118 | /** |
||
119 | * Initialization container |
||
120 | * |
||
121 | * @access protected |
||
122 | * @return void |
||
123 | */ |
||
124 | protected function initializeContainer() |
||
143 | |||
144 | /** |
||
145 | * Get full class name |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function getContainerClass() |
||
152 | |||
153 | /** |
||
154 | * Default config path |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function getConfig() |
||
162 | |||
163 | /** |
||
164 | * Get application directory |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getAppDir() |
||
176 | |||
177 | /** |
||
178 | * Add listener on event |
||
179 | * |
||
180 | * @access public |
||
181 | * |
||
182 | * @param string $listener listener name |
||
183 | * @param mixed $event ['Object', 'method'] or callable |
||
184 | * @param int|null $prior priority |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | protected function addListener($listener, $event, $prior = null) |
||
198 | |||
199 | /** |
||
200 | * Send signal to dispatcher |
||
201 | * |
||
202 | * @param $signal |
||
203 | * @param $params |
||
204 | * @return mixed |
||
205 | */ |
||
206 | protected function sendSignal($signal, $params) |
||
210 | |||
211 | /** |
||
212 | * Get start time |
||
213 | * |
||
214 | * @access public |
||
215 | * |
||
216 | * @return float|null |
||
217 | */ |
||
218 | public function getStartTime() |
||
222 | |||
223 | /** |
||
224 | * Starting ... |
||
225 | * |
||
226 | * @access private |
||
227 | * |
||
228 | * @param IRequest $request |
||
229 | * |
||
230 | * @return Web\IResponse|Response|string |
||
231 | * @throws \Micro\Base\Exception |
||
232 | */ |
||
233 | private function doRun(IRequest $request) |
||
281 | |||
282 | /** |
||
283 | * Get resolver |
||
284 | * |
||
285 | * @access protected |
||
286 | * |
||
287 | * @return IResolver |
||
288 | * @throws \Micro\Base\Exception |
||
289 | */ |
||
290 | protected function getResolver() |
||
308 | |||
309 | /** |
||
310 | * Do exception |
||
311 | * |
||
312 | * @access private |
||
313 | * |
||
314 | * @param \Exception $e Exception |
||
315 | * |
||
316 | * @return IOutput |
||
317 | * @throws \Micro\base\Exception |
||
318 | */ |
||
319 | private function doException(\Exception $e) |
||
349 | |||
350 | /** |
||
351 | * Terminate application |
||
352 | * |
||
353 | * @access public |
||
354 | * |
||
355 | * @return void |
||
356 | */ |
||
357 | public function terminate() |
||
361 | |||
362 | /** |
||
363 | * Get status of debug |
||
364 | * |
||
365 | * @access public |
||
366 | * |
||
367 | * @return bool |
||
368 | */ |
||
369 | public function isDebug() |
||
373 | |||
374 | /** |
||
375 | * Get components container |
||
376 | * |
||
377 | * @access public |
||
378 | * |
||
379 | * @return IContainer |
||
380 | */ |
||
381 | public function getContainer() |
||
385 | |||
386 | /** |
||
387 | * Get character set |
||
388 | * |
||
389 | * @access public |
||
390 | * |
||
391 | * @return string |
||
392 | */ |
||
393 | public function getCharset() |
||
397 | |||
398 | /** |
||
399 | * Get logs directory |
||
400 | * |
||
401 | * @return string |
||
402 | */ |
||
403 | public function getLogDir() |
||
407 | |||
408 | /** |
||
409 | * Get cache directory |
||
410 | * |
||
411 | * @return string |
||
412 | */ |
||
413 | public function getCacheDir() |
||
417 | |||
418 | /** |
||
419 | * Get environment name |
||
420 | * |
||
421 | * @access public |
||
422 | * |
||
423 | * @return string |
||
424 | */ |
||
425 | public function getEnvironment() |
||
429 | } |
||
430 |