| Conditions | 16 |
| Paths | 228 |
| Total Lines | 62 |
| Code Lines | 41 |
| Lines | 10 |
| Ratio | 16.13 % |
| Changes | 2 | ||
| Bugs | 1 | 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 | View Code Duplication | 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 | |||
| 150 | // try to initialize class object |
||
| 151 | View Code Duplication | if (class_exists($cName)) { |
|
| 152 | $callClass = new $cName; |
||
| 153 | } else { |
||
| 154 | throw new NotFoundException('Application can not be runned. Initialized class not founded: ' . App::$Security->strip_tags($cName)); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | // try to call method of founded callback class |
||
| 159 | if (method_exists($callClass, $callMethod)) { |
||
| 160 | $response = null; |
||
| 161 | // param "id" is passed |
||
| 162 | if (!Str::likeEmpty(self::$Request->getID())) { |
||
| 163 | // param "add" is passed |
||
| 164 | if (!Str::likeEmpty(self::$Request->getAdd())) { |
||
| 165 | $response = $callClass->$callMethod(self::$Request->getID(), self::$Request->getAdd()); |
||
| 166 | } else { |
||
| 167 | $response = $callClass->$callMethod(self::$Request->getID()); |
||
| 168 | } |
||
| 169 | } else { |
||
| 170 | // no passed params is founded |
||
| 171 | $response = $callClass->$callMethod(); |
||
| 172 | } |
||
| 173 | |||
| 174 | // work with returned response data |
||
| 175 | if ($response !== null && Obj::isString($response) && method_exists($callClass, 'setResponse')) { |
||
| 176 | $callClass->setResponse($response); |
||
| 177 | } |
||
| 178 | } else { |
||
| 179 | throw new NotFoundException('Method "' . $callMethod . '()" not founded in "' . get_class($callClass) . '"'); |
||
| 180 | } |
||
| 181 | } catch (NotFoundException $e) { |
||
| 182 | $e->display(); |
||
| 183 | } catch (ForbiddenException $e) { |
||
| 184 | $e->display(); |
||
| 185 | } catch (SyntaxException $e) { |
||
| 186 | $e->display(); |
||
| 187 | } catch (JsonException $e) { |
||
| 188 | $e->display(); |
||
| 189 | } catch (NativeException $e) { |
||
| 190 | $e->display(); |
||
| 191 | } catch (\Exception $e) { // catch all other exceptions |
||
| 192 | (new NativeException($e->getMessage()))->display(); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | } |
This check marks private properties in classes that are never used. Those properties can be removed.