Conditions | 14 |
Paths | 15 |
Total Lines | 50 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Tests | 36 |
CRAP Score | 14.0285 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | 5 | private function storeInCache($data) |
|
42 | { |
||
43 | 5 | file_put_contents($this->getCachePath(), '<?php return ' . var_export($data, true) . ';'); |
|
44 | 5 | } |
|
45 | |||
46 | public function readFromCache() |
||
47 | { |
||
48 | return include $this->getCachePath(); |
||
49 | } |
||
50 | |||
51 | 2 | public function clearCache() |
|
52 | { |
||
53 | 2 | unlink($this->getCachePath()); |
|
54 | 2 | } |
|
55 | |||
56 | 2 | public function cacheExists() |
|
57 | { |
||
58 | 2 | return file_exists($this->getCachePath()); |
|
59 | } |
||
60 | |||
61 | 5 | private function getCachePath(): string |
|
62 | { |
||
63 | 5 | return app()->bootstrapPath() . '/cache/' . $this->cacheFile; |
|
1 ignored issue
–
show
|
|||
64 | } |
||
65 | |||
66 | 5 | private function buildEmptyBootstrapArray() |
|
67 | { |
||
68 | 5 | $bootstrapArray = []; |
|
69 | 5 | foreach ($this->moduleEntityDirectories as $key => $directory) { |
|
70 | 5 | $bootstrapArray[$key] = []; |
|
71 | } |
||
72 | 5 | return $bootstrapArray; |
|
73 | } |
||
74 | |||
75 | 5 | private function buildBootstrapData() |
|
76 | { |
||
77 | 5 | $bootstrap = $this->buildEmptyBootstrapArray(); |
|
78 | 5 | foreach (\Module::all() as $module) { |
|
79 | 5 | foreach ($this->moduleEntityDirectories as $key => $directory) { |
|
80 | 5 | $directory = ucfirst($directory); |
|
81 | 5 | $directoryPath = $module->getPath() . '/' . $directory; |
|
82 | 5 | $namespace = 'Modules' . '\\' . $module->getName(); |
|
83 | 5 | if (file_exists($directoryPath)) { |
|
84 | 5 | $files = scandir($directoryPath); |
|
85 | 5 | foreach ($files as $fileName) { |
|
86 | 5 | if ($this->hasPhpExtension($fileName)) { |
|
87 | 5 | $className = basename($fileName, '.php'); |
|
88 | 5 | $class = $namespace . '\\' . str_replace('/', '\\', $directory) . '\\' . $className; |
|
89 | 5 | switch ($key) { |
|
90 | 5 | case 'commands': |
|
91 | try { |
||
208 |