Conditions | 6 |
Paths | 9 |
Total Lines | 31 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6.0702 |
Changes | 0 |
1 | <?php |
||
54 | 1 | public function load($className) |
|
55 | { |
||
56 | 1 | foreach ($this->addons as $addon) { |
|
57 | 1 | $namespace = $addon->phpNamespace(); |
|
58 | |||
59 | 1 | $namespacePrefix = $namespace ? $namespace.'\\' : ''; |
|
60 | |||
61 | // アドオンの名前空間下のクラスでないなら |
||
62 | 1 | if (!starts_with($className, $namespacePrefix)) { |
|
63 | 1 | continue; |
|
64 | } |
||
65 | |||
66 | // 名前空間を削る |
||
67 | 1 | $relativeClassName = substr($className, strlen($namespacePrefix)); |
|
68 | |||
69 | // クラスの相対パスを作成する(PSR-4) |
||
70 | 1 | $relativePath = $this->env->classToPath($relativeClassName); |
|
71 | |||
72 | // 全ディレクトリ下を探索する (PSR-4) |
||
73 | 1 | foreach ($addon->config('addon.directories') as $directory) { |
|
74 | 1 | $path = $addon->path($directory.'/'.$relativePath); |
|
75 | 1 | if (file_exists($path)) { |
|
76 | require_once $path; |
||
77 | |||
78 | return true; |
||
79 | } |
||
80 | 1 | } |
|
81 | 1 | } |
|
82 | |||
83 | 1 | return false; |
|
84 | } |
||
85 | } |
||
86 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.