Conditions | 12 |
Paths | 91 |
Total Lines | 46 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
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 declare(strict_types=1); |
||
69 | public function getModule(string $moduleName) : Module |
||
70 | { |
||
71 | // Check if module exists |
||
72 | if (!array_key_exists($moduleName, $this->composerModules)) { |
||
73 | throw new \Exception(sprintf('Module with name "%s" not found', $moduleName)); |
||
74 | } |
||
75 | |||
76 | $composerModule = $this->composerModules[$moduleName]; |
||
77 | $modulePath = $this->appPath . $this->vendorDir . $moduleName; |
||
78 | |||
79 | // Convert resource map to module type |
||
80 | $resourceMap = ResourceMap::get($modulePath); |
||
81 | |||
82 | // Get all module classes |
||
83 | $classes = []; |
||
84 | foreach ($resourceMap->classData as $classData) { |
||
85 | $classes[$classData['path']] = $classData['className']; |
||
86 | if (array_key_exists('implements', $classData)) { |
||
87 | foreach ($classData['implements'] as $interfaceName) { |
||
88 | $this->implements[$interfaceName] = $classData['className']; |
||
89 | } |
||
90 | } |
||
91 | if (array_key_exists('extends', $classData) && isset($classData['extends']{0})) { |
||
92 | $this->extends[$classData['extends']] = $classData['className']; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | foreach ($this->implements as $interface => $class) { |
||
97 | if (array_key_exists($class, $this->extends)) { |
||
98 | $this->implements[$interface] = $this->extends[$class]; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // Create new module |
||
103 | $module = new Module($moduleName, $modulePath, $classes); |
||
104 | $module->composerParameters = $composerModule; |
||
105 | if (isset($resourceMap->module[0])) { |
||
106 | $module->className = $resourceMap->module[0]; |
||
107 | $module->pathName = $resourceMap->module[1]; |
||
108 | } |
||
109 | $module->isVirtualModule = !array_key_exists(0, $resourceMap->module) && |
||
|
|||
110 | array_key_exists(self::COMPRESSABLE_MODULE_ID, $composerModule) && |
||
111 | (bool)$composerModule[self::COMPRESSABLE_MODULE_ID] === true; |
||
112 | |||
113 | return $module; |
||
114 | } |
||
115 | } |
||
116 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.