Total Complexity | 47 |
Total Lines | 181 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like StaticLoader 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.
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 StaticLoader, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class StaticLoader extends Module { |
||
12 | |||
13 | public $mimes = []; |
||
14 | |||
15 | public function init() { |
||
17 | } |
||
18 | |||
19 | public function parsePath($path) { |
||
20 | $path = Tools::parsePath($path); |
||
|
|||
21 | |||
22 | if (strpos($path, '/') === 0) { |
||
23 | $path = substr($path, 1); |
||
24 | } |
||
25 | $app = substr($path, 0, strpos($path, '/')); |
||
26 | |||
27 | if ($app && file_exists(INJI_SYSTEM_DIR . '/program/' . $app)) { |
||
28 | $path = substr($path, strpos($path, '/') + 1); |
||
29 | if (\App::$cur->name != $app) { |
||
30 | $scriptApp = new App(); |
||
31 | $scriptApp->name = $app; |
||
32 | $scriptApp->system = true; |
||
33 | $scriptApp->staticPath = "/" . $scriptApp->name . "/static"; |
||
34 | $scriptApp->templatesPath = "/" . $scriptApp->name . "/static/templates"; |
||
35 | $scriptApp->path = INJI_SYSTEM_DIR . '/program/' . $scriptApp->name; |
||
36 | $scriptApp->type = 'app' . ucfirst(strtolower($scriptApp->name)); |
||
37 | $scriptApp->installed = true; |
||
38 | $scriptApp->params = []; |
||
39 | $scriptApp->config = Config::app($scriptApp); |
||
40 | } else { |
||
41 | $scriptApp = \App::$cur; |
||
42 | } |
||
43 | } else { |
||
44 | $scriptApp = \App::$cur->system ? \App::$primary : \App::$cur; |
||
45 | } |
||
46 | |||
47 | if (strpos($path, 'static/') !== false && strpos($path, 'static/') <= 1) { |
||
48 | $path = substr($path, strpos($path, 'static') + 7); |
||
49 | } |
||
50 | |||
51 | $type = substr($path, 0, strpos($path, '/')); |
||
52 | switch ($type) { |
||
53 | case 'cache': |
||
54 | return INJI_BASE_DIR . $path; |
||
55 | case 'libs': |
||
56 | return App::$cur->Libs->getPath(array_slice(explode('/', $path), 2)); |
||
57 | case 'templates': |
||
58 | $path = substr($path, strpos($path, '/') + 1); |
||
59 | return $scriptApp->view->templatesPath . '/' . $path; |
||
60 | case 'system': |
||
61 | $path = substr($path, strpos($path, '/') + 1); |
||
62 | return INJI_SYSTEM_DIR . '/static/' . $path; |
||
63 | case 'moduleAsset': |
||
64 | $path = substr($path, strpos($path, '/') + 1); |
||
65 | if (!strpos($path, '/')) { |
||
66 | return false; |
||
67 | } |
||
68 | $module = substr($path, 0, strpos($path, '/')); |
||
69 | |||
70 | if (!$scriptApp->$module) { |
||
71 | return false; |
||
72 | } |
||
73 | $path = substr($path, strpos($path, '/') + 1); |
||
74 | if (is_callable([$module, 'staticCalled'])) { |
||
75 | return $scriptApp->$module->staticCalled($path, $scriptApp->$module->path . '/static/'); |
||
76 | } |
||
77 | return $scriptApp->$module->path . '/static/' . $path; |
||
78 | default: |
||
79 | return $scriptApp->path . '/static/' . $path; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | public function giveFile($file) { |
||
192 | } |
||
193 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths