| Conditions | 12 |
| Paths | 11 |
| Total Lines | 64 |
| Code Lines | 44 |
| 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 |
||
| 59 | public function render($request, Exception $exception) |
||
| 60 | { |
||
| 61 | if ($exception instanceof TokenMismatchException) { |
||
| 62 | return intend([ |
||
| 63 | 'back' => true, |
||
| 64 | 'with' => ['warning' => trans('cortex/foundation::messages.token_mismatch')], |
||
| 65 | ]); |
||
| 66 | } elseif ($exception instanceof WatsonValidationException) { |
||
| 67 | return intend([ |
||
| 68 | 'back' => true, |
||
| 69 | 'withInput' => $request->all(), |
||
| 70 | 'withErrors' => $exception->errors(), |
||
| 71 | ]); |
||
| 72 | } elseif ($exception instanceof ValidationException) { |
||
| 73 | return intend([ |
||
| 74 | 'back' => true, |
||
| 75 | 'withInput' => $request->all(), |
||
| 76 | 'withErrors' => $exception->errors(), |
||
| 77 | ]); |
||
| 78 | } elseif ($exception instanceof GenericException) { |
||
| 79 | return intend([ |
||
| 80 | 'url' => $exception->getRedirection() ?? route($request->get('accessarea').'.home'), |
||
| 81 | 'withInput' => $exception->getInputs() ?? $request->all(), |
||
| 82 | 'with' => ['warning' => $exception->getMessage()], |
||
| 83 | ]); |
||
| 84 | } elseif ($exception instanceof AuthorizationException) { |
||
| 85 | return intend([ |
||
| 86 | 'url' => route($request->get('accessarea').'.home'), |
||
| 87 | 'with' => ['warning' => $exception->getMessage()], |
||
| 88 | ]); |
||
| 89 | } elseif ($exception instanceof NotFoundHttpException) { |
||
| 90 | // Catch localized routes with missing {locale} |
||
| 91 | // and redirect them to the correct localized version |
||
| 92 | if (config('cortex.foundation.route.locale_redirect')) { |
||
| 93 | $originalUrl = $request->url(); |
||
| 94 | $localizedUrl = app('laravellocalization')->getLocalizedURL(null, $originalUrl); |
||
| 95 | |||
| 96 | try { |
||
| 97 | // Will return `NotFoundHttpException` exception if no match found! |
||
| 98 | app('router')->getRoutes()->match(request()->create($localizedUrl)); |
||
| 99 | |||
| 100 | return intend([ |
||
| 101 | 'url' => $originalUrl !== $localizedUrl ? $localizedUrl : route($request->get('accessarea').'.home'), |
||
|
|
|||
| 102 | 'with' => ['warning' => $exception->getMessage()], |
||
| 103 | ]); |
||
| 104 | } catch (Exception $exception) { |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | return $this->prepareResponse($request, $exception); |
||
| 109 | } elseif ($exception instanceof ModelNotFoundException) { |
||
| 110 | $area = $request->get('accessarea'); |
||
| 111 | $model = str_replace('Contract', '', $exception->getModel()); |
||
| 112 | $single = mb_strtolower(mb_substr($model, mb_strrpos($model, '\\') + 1)); |
||
| 113 | $plural = str_plural($single); |
||
| 114 | |||
| 115 | return intend([ |
||
| 116 | 'url' => $area ? route("{$area}.{$plural}.index") : route("{$area}.home"), |
||
| 117 | 'with' => ['warning' => trans('cortex/foundation::messages.resource_not_found', ['resource' => $single, 'id' => $request->route()->parameter($single)])], |
||
| 118 | ]); |
||
| 119 | } |
||
| 120 | |||
| 121 | return parent::render($request, $exception); |
||
| 122 | } |
||
| 123 | |||
| 177 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.