| Conditions | 16 |
| Paths | 300 |
| Total Lines | 50 |
| Code Lines | 29 |
| 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 |
||
| 81 | private function loadModule($loadModule) |
||
| 82 | { |
||
| 83 | $loadModuleName = lcfirst($loadModule); |
||
| 84 | //checking for module in namespace, app and core. |
||
| 85 | $loadModuleObj = ''; |
||
| 86 | $found = false; |
||
| 87 | $childClassNamespace = new \ReflectionClass(get_class($this)); |
||
| 88 | $childClassNamespace = $childClassNamespace->getNamespaceName(); |
||
| 89 | //check in classNameSpace, make sure we are not already in App or core |
||
| 90 | if (class_exists($childClassNamespace . '\\Modules\\' . $loadModule)) { |
||
| 91 | if($childClassNamespace !== 'App\\Modules\\' || $childClassNamespace !== 'Core\\Modules\\'){ |
||
| 92 | $loadModuleObj = $childClassNamespace . '\\' . $loadModule; |
||
| 93 | $found = true; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | //check in app |
||
| 97 | if (class_exists('App\\Modules\\' . $loadModule)) { |
||
| 98 | if($found && Config::DEV_ENVIRONMENT){ |
||
| 99 | $this->alertBox->setAlert($loadModule.' already defined in namespace', 'error'); |
||
| 100 | } |
||
| 101 | if(!$found){ |
||
| 102 | $loadModuleObj = 'App\\Modules\\' . $loadModule; |
||
| 103 | $found = true; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | //check in core, send error popup if overcharged |
||
| 107 | if (class_exists('Core\\Modules\\' . $loadModule)) { |
||
| 108 | if($found && Config::DEV_ENVIRONMENT){ |
||
| 109 | $this->alertBox->setAlert($loadModule.' already defined in app', 'error'); |
||
| 110 | } |
||
| 111 | if(!$found){ |
||
| 112 | $loadModuleObj = 'Core\\Modules\\' . $loadModule; |
||
| 113 | $found = true; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | if(!$found || $loadModuleObj ==='') { |
||
| 117 | throw new \ErrorException('module ' . $loadModule . ' does not exist or not loaded'); |
||
| 118 | } |
||
| 119 | |||
| 120 | //Modules must be children of the Module template |
||
| 121 | if (!is_subclass_of($loadModuleObj, 'Core\Modules\Module')) { |
||
| 122 | throw new \ErrorException('Module ' . $loadModuleName . ' must be a sub class of module'); |
||
| 123 | } |
||
| 124 | |||
| 125 | $loadedModule = new $loadModuleObj($this->container); |
||
| 126 | //we are not allowed to create public modules, they must be a placeholder ready |
||
| 127 | if (!property_exists($this, $loadModuleName)) { |
||
| 128 | throw new \ErrorException('the protected or private variable of ' . $loadModuleName . ' is not present'); |
||
| 129 | } |
||
| 130 | $this->$loadModuleName = $loadedModule; |
||
| 131 | } |
||
| 198 | } |