Total Complexity | 62 |
Total Lines | 437 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Complex classes like AbstractPosition 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 AbstractPosition, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | abstract class AbstractPosition |
||
28 | { |
||
29 | /** |
||
30 | * AbstractPosition::__get |
||
31 | * |
||
32 | * @param string $property |
||
33 | * |
||
34 | * @return \O2System\Framework\Http\Presenter\Assets\Collections\Css|\O2System\Framework\Http\Presenter\Assets\Collections\Font|\O2System\Framework\Http\Presenter\Assets\Collections\Javascript|null |
||
|
|||
35 | */ |
||
36 | public function __get($property) |
||
37 | { |
||
38 | return isset($this->{$property}) ? $this->{$property} : null; |
||
39 | } |
||
40 | |||
41 | // ------------------------------------------------------------------------ |
||
42 | |||
43 | /** |
||
44 | * AbstractPosition::getUrl |
||
45 | * |
||
46 | * @param string $realPath |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getUrl($realPath) |
||
51 | { |
||
52 | if (strpos($realPath, 'http') !== false) { |
||
53 | return $realPath; |
||
54 | } |
||
55 | |||
56 | return (new Uri()) |
||
57 | ->withQuery(null) |
||
58 | ->withSegments( |
||
59 | new Uri\Segments( |
||
60 | str_replace( |
||
61 | [PATH_PUBLIC, DIRECTORY_SEPARATOR], |
||
62 | ['', '/'], |
||
63 | $realPath |
||
64 | ) |
||
65 | ) |
||
66 | ) |
||
67 | ->__toString(); |
||
68 | } |
||
69 | |||
70 | // ------------------------------------------------------------------------ |
||
71 | |||
72 | /** |
||
73 | * AbstractPosition::loadCollections |
||
74 | * |
||
75 | * @param array $collections |
||
76 | */ |
||
77 | public function loadCollections(array $collections) |
||
78 | { |
||
79 | foreach ($collections as $subDir => $files) { |
||
80 | if (is_array($files) and count($files)) { |
||
81 | |||
82 | // normalize the subDirectory with a trailing separator |
||
83 | $subDir = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $subDir); |
||
84 | $subDir = rtrim($subDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
||
85 | |||
86 | foreach ($files as $file) { |
||
87 | if (strpos($file, 'http') !== false) { |
||
88 | $this->loadUrl($file, $subDir); |
||
89 | } else { |
||
90 | $this->loadFile($file, $subDir); |
||
91 | } |
||
92 | } |
||
93 | } elseif (is_string($files)) { |
||
94 | $this->loadFile($files); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | // ------------------------------------------------------------------------ |
||
100 | |||
101 | /** |
||
102 | * AbstractPosition::loadUrl |
||
103 | * |
||
104 | * @param string $url |
||
105 | * @param string|null $subDir |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function loadUrl($url, $subDir = null) |
||
110 | { |
||
111 | $property = is_null($subDir) ? 'css' : null; |
||
112 | |||
113 | if (is_null($property)) { |
||
114 | switch ($subDir) { |
||
115 | default: |
||
116 | case 'css/': |
||
117 | $property = 'css'; |
||
118 | break; |
||
119 | case 'font/': |
||
120 | case 'fonts/': |
||
121 | $property = 'font'; |
||
122 | break; |
||
123 | case 'js/': |
||
124 | $property = 'javascript'; |
||
125 | break; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | if (property_exists($this, $property)) { |
||
130 | if ( ! call_user_func_array([$this->{$property}, 'has'], [$url])) { |
||
131 | $this->{$property}->append($url); |
||
132 | |||
133 | return true; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | return false; |
||
138 | } |
||
139 | |||
140 | // ------------------------------------------------------------------------ |
||
141 | |||
142 | /** |
||
143 | * AbstractPosition::loadFile |
||
144 | * |
||
145 | * @param string $filename |
||
146 | * @param string|null $subDir |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | abstract public function loadFile($filename, $subDir = null); |
||
151 | |||
152 | // ------------------------------------------------------------------------ |
||
153 | |||
154 | /** |
||
155 | * AbstractPosition::publishFile |
||
156 | * |
||
157 | * @param $filePath |
||
158 | * |
||
159 | * @return array |
||
160 | */ |
||
161 | protected function publishFile($filePath) |
||
257 | ]; |
||
258 | } |
||
259 | |||
260 | // ------------------------------------------------------------------------ |
||
261 | |||
262 | /** |
||
263 | * AbstractPosition::bundleFile |
||
264 | * |
||
265 | * @param string $filename |
||
266 | * @param array $sources |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | protected function bundleFile($filename, array $sources) |
||
368 | ]; |
||
369 | } |
||
370 | |||
371 | // ------------------------------------------------------------------------ |
||
372 | |||
373 | /** |
||
374 | * AbstractPosition::getFilePath |
||
375 | * |
||
376 | * @param string $filename |
||
377 | * @param string|null $subDir |
||
378 | * |
||
379 | * @return string |
||
380 | */ |
||
381 | protected function getFilePath($filename, $subDir = null) |
||
382 | { |
||
383 | $directories = presenter()->assets->getFilePaths(); |
||
384 | |||
385 | foreach ($directories as $directory) { |
||
386 | if (strpos($filename, 'app') !== false) { |
||
387 | if ($app = modules()->getActiveApp()) { |
||
388 | $directory = $app->getResourcesDir(); |
||
389 | } |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * Try with sub directory |
||
394 | * find from public directory first then resource directory |
||
395 | */ |
||
396 | if (isset($subDir)) { |
||
397 | $subDir = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $subDir); |
||
398 | |||
399 | if (is_file($filePath = str_replace(PATH_RESOURCES, PATH_PUBLIC, |
||
400 | $directory) . $subDir . $filename)) { |
||
401 | return $filePath; |
||
402 | break; |
||
403 | } elseif (is_file($filePath = str_replace(PATH_RESOURCES, PATH_PUBLIC . 'assets' . DIRECTORY_SEPARATOR, |
||
404 | $directory) . $subDir . $filename)) { |
||
405 | return $filePath; |
||
406 | break; |
||
407 | } elseif (is_file($filePath = $directory . $subDir . $filename)) { |
||
408 | return $filePath; |
||
409 | break; |
||
410 | } |
||
411 | } |
||
412 | |||
413 | /** |
||
414 | * Try without sub directory |
||
415 | * find from public directory first then resource directory |
||
416 | */ |
||
417 | if (is_file($filePath = str_replace(PATH_RESOURCES, PATH_PUBLIC, $directory) . $filename)) { |
||
418 | return $filePath; |
||
419 | break; |
||
420 | } elseif (is_file($filePath = str_replace(PATH_RESOURCES, PATH_PUBLIC . 'assets' . DIRECTORY_SEPARATOR, |
||
421 | $directory) . $filename)) { |
||
422 | return $filePath; |
||
423 | break; |
||
424 | } elseif (is_file($filePath = $directory . $filename)) { |
||
425 | return $filePath; |
||
426 | break; |
||
427 | } |
||
428 | } |
||
429 | |||
430 | return false; |
||
431 | } |
||
432 | |||
433 | // ------------------------------------------------------------------------ |
||
434 | |||
435 | /** |
||
436 | * AbstractPosition::getVersion |
||
437 | * |
||
438 | * @param string $code |
||
439 | * |
||
440 | * @return string |
||
441 | */ |
||
442 | public function getVersion($codeSerialize) |
||
454 | } |
||
455 | |||
456 | // ------------------------------------------------------------------------ |
||
457 | |||
458 | /** |
||
459 | * AbstractPosition::__toString |
||
460 | * |
||
461 | * @return string |
||
462 | */ |
||
463 | abstract public function __toString(); |
||
464 | } |
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