| Conditions | 10 |
| Paths | 11 |
| Total Lines | 70 |
| Code Lines | 45 |
| 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 |
||
| 168 | public function prepareExceptionViewModel(MvcEvent $e) |
||
| 169 | { |
||
| 170 | // Do nothing if no error in the event |
||
| 171 | $error = $e->getError(); |
||
| 172 | if (empty($error)) { |
||
| 173 | return; |
||
| 174 | } |
||
| 175 | |||
| 176 | // Do nothing if the result is a response object |
||
| 177 | $result = $e->getResult(); |
||
| 178 | if ($result instanceof ResponseInterface) { |
||
|
1 ignored issue
–
show
|
|||
| 179 | return; |
||
| 180 | } |
||
| 181 | |||
| 182 | // Proceed to showing an error page with or without exception |
||
| 183 | switch ($error) { |
||
| 184 | case Application::ERROR_CONTROLLER_NOT_FOUND: |
||
| 185 | case Application::ERROR_CONTROLLER_INVALID: |
||
| 186 | case Application::ERROR_ROUTER_NO_MATCH: |
||
| 187 | // Specifically not handling these |
||
| 188 | return; |
||
| 189 | |||
| 190 | case Application::ERROR_EXCEPTION: |
||
| 191 | default: |
||
| 192 | // Prepare error message |
||
| 193 | $exception = $e->getParam('exception'); |
||
| 194 | |||
| 195 | // Log exception to sentry by triggering an exception event |
||
| 196 | $e->getApplication()->getEventManager()->trigger('logException', $this, array('exception' => $exception)); |
||
| 197 | |||
| 198 | if (is_callable($this->message)) { |
||
| 199 | $callback = $this->message; |
||
| 200 | $message = (string) $callback($exception, $this->displayExceptions); |
||
| 201 | } elseif ($this->displayExceptions && $exception instanceof \Exception) { |
||
| 202 | /* @var $exception \Exception */ |
||
| 203 | $message = str_replace( |
||
| 204 | array( |
||
| 205 | ':className', |
||
| 206 | ':message', |
||
| 207 | ':code', |
||
| 208 | ':file', |
||
| 209 | ':line', |
||
| 210 | ':stack', |
||
| 211 | ':previous', |
||
| 212 | ), array( |
||
| 213 | get_class($exception), |
||
| 214 | $exception->getMessage(), |
||
| 215 | $exception->getCode(), |
||
| 216 | $exception->getFile(), |
||
| 217 | $exception->getLine(), |
||
| 218 | $exception->getTraceAsString(), |
||
| 219 | $exception->getPrevious(), |
||
| 220 | ), |
||
| 221 | $this->message |
||
| 222 | ); |
||
| 223 | } else { |
||
| 224 | $message = $this->defaultExceptionMessage; |
||
| 225 | } |
||
| 226 | |||
| 227 | // Prepare view model |
||
| 228 | $model = new ConsoleModel(); |
||
| 229 | $model->setResult($message); |
||
| 230 | $model->setErrorLevel(1); |
||
| 231 | |||
| 232 | // Inject it into MvcEvent |
||
| 233 | $e->setResult($model); |
||
| 234 | |||
| 235 | break; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
|
1 ignored issue
–
show
|
|||
| 239 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.