Complex classes like Module 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 Module, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class Module { |
||
12 | |||
13 | /** |
||
14 | * Storage of cur requested module |
||
15 | * |
||
16 | * @var \Module |
||
17 | */ |
||
18 | public static $cur = null; |
||
19 | |||
20 | /** |
||
21 | * Module name |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $moduleName = ''; |
||
26 | |||
27 | /** |
||
28 | * Module config |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | public $config = []; |
||
33 | |||
34 | /** |
||
35 | * Module info |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | public $info = []; |
||
40 | |||
41 | /** |
||
42 | * Requested module params |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | public $params = []; |
||
47 | |||
48 | /** |
||
49 | * Module directory path |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | public $path = ''; |
||
54 | |||
55 | /** |
||
56 | * Module app |
||
57 | * |
||
58 | * @var \App |
||
59 | */ |
||
60 | public $app = null; |
||
61 | |||
62 | /** |
||
63 | * Parse cur module |
||
64 | * |
||
65 | * @param \App $app |
||
66 | */ |
||
67 | public function __construct($app) { |
||
79 | |||
80 | /** |
||
81 | * Get all posible directorys for module files |
||
82 | * |
||
83 | * @param string $moduleName |
||
84 | * @return array |
||
85 | */ |
||
86 | public static function getModulePaths($moduleName) { |
||
96 | |||
97 | /** |
||
98 | * Return directory where places module file |
||
99 | * |
||
100 | * @param string $moduleName |
||
101 | * @return string |
||
102 | */ |
||
103 | public static function getModulePath($moduleName) { |
||
112 | |||
113 | /** |
||
114 | * Check module for installed |
||
115 | * |
||
116 | * @param string $moduleName |
||
117 | * @param \App $app |
||
118 | * @return boolean |
||
119 | */ |
||
120 | public static function installed($moduleName, $app) { |
||
126 | |||
127 | /** |
||
128 | * Get installed modules for app |
||
129 | * |
||
130 | * @param \App $app |
||
131 | * @param App $primary |
||
132 | * @return array |
||
133 | */ |
||
134 | public static function getInstalled($app, $primary = false) { |
||
144 | |||
145 | /** |
||
146 | * Find module controllers |
||
147 | * |
||
148 | * @param string $moduleName |
||
149 | * @return array |
||
150 | */ |
||
151 | public static function getModuleControllers($moduleName) { |
||
171 | |||
172 | /** |
||
173 | * Find module by request |
||
174 | * |
||
175 | * @param \App $app |
||
176 | * @param array|null $params |
||
177 | * @return \Module |
||
178 | */ |
||
179 | public static function resolveModule($app, $params = null) { |
||
200 | |||
201 | /** |
||
202 | * Get posible path for controller |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | public function getControllerPaths() { |
||
238 | |||
239 | /** |
||
240 | * Find controller by request |
||
241 | * |
||
242 | * @return \Controller |
||
243 | */ |
||
244 | public function findController() { |
||
266 | |||
267 | /** |
||
268 | * Return module info |
||
269 | * |
||
270 | * @param string $moduleName |
||
271 | * @return array |
||
272 | */ |
||
273 | public static function getInfo($moduleName = '') { |
||
287 | |||
288 | /** |
||
289 | * Return snippets by name |
||
290 | * |
||
291 | * @param string $snippetsPath |
||
292 | * @param boolean $extensions |
||
293 | * @param string $dir |
||
294 | * @param string $moduleName |
||
295 | * @return array |
||
296 | */ |
||
297 | public function getSnippets($snippetsPath, $extensions = true, $dir = '/snippets', $moduleName = '') { |
||
320 | |||
321 | /** |
||
322 | * Return extensions for type |
||
323 | * |
||
324 | * @param string $extensionType |
||
325 | * @param string $request |
||
326 | * @return array |
||
327 | */ |
||
328 | public function getExtensions($extensionType, $request) { |
||
337 | |||
338 | public function checkDbMigration() { |
||
349 | |||
350 | public function sitemap() { |
||
353 | } |