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