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 declare(strict_types=1); |
||
52 | class Core implements SystemInterface |
||
53 | { |
||
54 | /** @deprecated Standard algorithm for view rendering */ |
||
55 | const RENDER_STANDART = 1; |
||
56 | /** @deprecated View rendering algorithm from array of view variables */ |
||
57 | const RENDER_VARIABLE = 3; |
||
58 | /** @deprecated @var ResourceMap Current web-application resource map */ |
||
59 | public $map; |
||
60 | /** @deprecated @var string Path to current web-application */ |
||
61 | public $system_path = __SAMSON_CWD__; |
||
62 | |||
63 | /* Rendering models */ |
||
64 | /** @deprecated @var string View path loading mode */ |
||
65 | public $render_mode = self::RENDER_STANDART; |
||
66 | /** @var ContainerInterface */ |
||
67 | protected $container; |
||
68 | /** @var ClassMetadata[] */ |
||
69 | protected $metadataCollection = []; |
||
70 | /** @var ContainerBuilderInterface */ |
||
71 | protected $builder; |
||
72 | /** @var string Current system environment */ |
||
73 | protected $environment; |
||
74 | protected $classes = []; |
||
75 | /** @var Module Pointer to current active module */ |
||
76 | protected $active = null; |
||
77 | /** @var bool Flag for outputting layout template, used for asynchronous requests */ |
||
78 | protected $async = false; |
||
79 | /** @var string Path to main system template */ |
||
80 | protected $template_path = __SAMSON_DEFAULT_TEMPLATE; |
||
81 | |||
82 | /** |
||
83 | * Core constructor. |
||
84 | * |
||
85 | * @param ContainerBuilderInterface $builder Container builder |
||
86 | * @param ResourceMap|null $map system resources |
||
87 | * @InjectService(container="container") |
||
88 | * InjectArgument(builder="samsonframework\container\ContainerBuilderInterface") |
||
89 | * InjectArgument(builder="samsonframework\core\ResourceInterface") |
||
90 | */ |
||
91 | public function __construct(ContainerInterface $container, ContainerBuilderInterface $builder = null, ResourceMap $map = null) |
||
110 | 1 | ||
111 | /** |
||
112 | * Generic wrap for Event system subscription. |
||
113 | * @see \samson\core\\samsonphp\event\Event::subscribe() |
||
114 | * |
||
115 | * @param string $key Event identifier |
||
116 | * @param callable $handler Event handler |
||
117 | * @param array $params Event parameters |
||
118 | * |
||
119 | * @return $this Chaining |
||
120 | */ |
||
121 | 1 | public function subscribe($key, $handler, $params = array()) |
|
127 | |||
128 | /** |
||
129 | * Change current system working environment or receive |
||
130 | * current system enviroment if no arguments are passed. |
||
131 | * |
||
132 | * @param string $environment Environment identifier |
||
133 | * |
||
134 | * TODO: Function has two different logics - needs to be changed! |
||
135 | * @return $this|string Chaining or current system environment |
||
136 | */ |
||
137 | public function environment($environment = Scheme::BASE) |
||
149 | |||
150 | /** |
||
151 | * Generate special response header triggering caching mechanisms |
||
152 | * @param int $cacheLife Amount of seconds for cache(default 3600 - 1 hour) |
||
153 | * @param string $accessibility Cache-control accessibility value(default public) |
||
154 | */ |
||
155 | public function cached($cacheLife = 3600, $accessibility = 'public') |
||
167 | |||
168 | /** |
||
169 | * Set asynchronous mode. |
||
170 | * This mode will not output template and will just path everything that |
||
171 | * was outputted to client. |
||
172 | * |
||
173 | * @param bool $async True to switch to asynchronous output mode |
||
174 | * |
||
175 | * @return $this Chaining |
||
176 | */ |
||
177 | public function async($async) |
||
183 | |||
184 | /** @see iModule::active() */ |
||
185 | public function active($module = null) |
||
198 | |||
199 | /** |
||
200 | * Retrieve module instance by identifier. |
||
201 | * |
||
202 | * @param string|null $module Module identifier |
||
203 | * |
||
204 | * @return null|Module Found or active module |
||
205 | */ |
||
206 | public function module($module = null) |
||
226 | |||
227 | /** |
||
228 | * Unload module from core. |
||
229 | * |
||
230 | * @param string $moduleID Module identifier |
||
231 | */ |
||
232 | public function unload($moduleID) |
||
238 | |||
239 | /** |
||
240 | * Insert generic html template tags and data |
||
241 | * |
||
242 | * @param string $templateHtml Generated HTML |
||
243 | * |
||
244 | * @deprecated Must be moved to a new HTML output object |
||
245 | * @return mixed Changed HTML template |
||
246 | */ |
||
247 | public function generateTemplate(&$templateHtml) |
||
269 | |||
270 | /** |
||
271 | 2 | * Start SamsonPHP framework. |
|
272 | * |
||
273 | * @param string $default Default module identifier |
||
274 | 2 | * |
|
275 | * @throws ViewPathNotFound |
||
276 | */ |
||
277 | public function start($default) |
||
328 | |||
329 | 2 | /** @see iCore::template() */ |
|
330 | public function template($template = NULL, $absolutePath = false) |
||
340 | |||
341 | /** |
||
342 | * Render file to a buffer. |
||
343 | * |
||
344 | * @param string $view Path to file |
||
345 | * @param array $data Collection of variables to path to file |
||
346 | * |
||
347 | * @return string Rendered file contents |
||
348 | * @throws ViewPathNotFound |
||
349 | */ |
||
350 | public function render($view, $data = array()) |
||
414 | 2 | ||
415 | /** |
||
416 | * Load system from composer.json |
||
417 | * @param string $dependencyFilePath Path to dependencies file |
||
418 | * @return $this Chaining |
||
419 | * @deprecated |
||
420 | */ |
||
421 | public function composer($dependencyFilePath = null) |
||
428 | |||
429 | |||
430 | //[PHPCOMPRESSOR(remove,start)] |
||
431 | |||
432 | /** @see iCore::path() */ |
||
433 | public function path($path = null) |
||
450 | |||
451 | //[PHPCOMPRESSOR(remove,end)] |
||
452 | |||
453 | /** @return \Container Get system container */ |
||
454 | public function getContainer() |
||
458 | |||
459 | /** Магический метод для десериализации объекта */ |
||
460 | public function __wakeup() |
||
464 | |||
465 | /** Магический метод для сериализации объекта */ |
||
466 | public function __sleep() |
||
470 | } |
||
471 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.