| Conditions | 17 |
| Paths | 252 |
| Total Lines | 69 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 133 | public static function run() |
||
| 134 | { |
||
| 135 | try { |
||
| 136 | $callClass = null; |
||
| 137 | $callMethod = 'action' . self::$Request->getAction(); |
||
| 138 | |||
| 139 | // founded callback injection alias |
||
| 140 | if (self::$Request->getCallbackAlias() !== false) { |
||
| 141 | $cName = self::$Request->getCallbackAlias(); |
||
| 142 | if (class_exists($cName)) { |
||
| 143 | $callClass = new $cName; |
||
| 144 | } else { |
||
| 145 | throw new NotFoundException('Callback alias of class "' . App::$Security->strip_tags($cName) . '" is not founded'); |
||
| 146 | } |
||
| 147 | } else { // typical parsing of native apps |
||
| 148 | $cName = '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController(); |
||
| 149 | $cPath = Str::replace('\\', '/', $cName) . '.php'; |
||
| 150 | |||
| 151 | // try to load controller |
||
| 152 | if (File::exist($cPath)) { |
||
| 153 | File::inc($cPath, false, true); |
||
| 154 | } else { |
||
| 155 | throw new NotFoundException('Controller not founded: {root}' . $cPath); |
||
| 156 | } |
||
| 157 | // try to initialize class object |
||
| 158 | if (class_exists($cName)) { |
||
| 159 | $callClass = new $cName; |
||
| 160 | } else { |
||
| 161 | throw new NotFoundException('App is not founded: "' . $cName . '. Pathway: {root}' . $cPath); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | // try to call method of founded callback class |
||
| 166 | if (method_exists($callClass, $callMethod)) { |
||
| 167 | $response = null; |
||
| 168 | // param "id" is passed |
||
| 169 | if (!Str::likeEmpty(self::$Request->getID())) { |
||
| 170 | // param "add" is passed |
||
| 171 | if (!Str::likeEmpty(self::$Request->getAdd())) { |
||
| 172 | $response = $callClass->$callMethod(self::$Request->getID(), self::$Request->getAdd()); |
||
| 173 | } else { |
||
| 174 | $response = $callClass->$callMethod(self::$Request->getID()); |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | // no passed params is founded |
||
| 178 | $response = $callClass->$callMethod(); |
||
| 179 | } |
||
| 180 | |||
| 181 | // work with returned response data |
||
| 182 | if ($response !== null && Obj::isString($response) && method_exists($callClass, 'setResponse')) { |
||
| 183 | $callClass->setResponse($response); |
||
| 184 | } |
||
| 185 | } else { |
||
| 186 | throw new NotFoundException('Method "' . $callMethod . '()" not founded in "' . get_class($callClass) . '"'); |
||
| 187 | } |
||
| 188 | } catch (NotFoundException $e) { |
||
| 189 | $e->display(); |
||
| 190 | } catch (ForbiddenException $e) { |
||
| 191 | $e->display(); |
||
| 192 | } catch (SyntaxException $e) { |
||
| 193 | $e->display(); |
||
| 194 | } catch (JsonException $e) { |
||
| 195 | $e->display(); |
||
| 196 | } catch (NativeException $e) { |
||
| 197 | $e->display(); |
||
| 198 | } catch(\Exception $e) { // catch all other exceptions |
||
| 199 | (new NativeException($e->getMessage()))->display(); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | } |
This check marks private properties in classes that are never used. Those properties can be removed.