Conditions | 13 |
Paths | 12 |
Total Lines | 66 |
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 |
||
45 | public function render($request, Exception $exception) |
||
46 | { |
||
47 | $accessarea = str_before(Route::currentRouteName(), '.'); |
||
|
|||
48 | |||
49 | if ($exception instanceof TokenMismatchException) { |
||
50 | return intend([ |
||
51 | 'back' => true, |
||
52 | 'with' => ['warning' => trans('cortex/foundation::messages.token_mismatch')], |
||
53 | ]); |
||
54 | } elseif ($exception instanceof WatsonValidationException) { |
||
55 | return intend([ |
||
56 | 'back' => true, |
||
57 | 'withInput' => $request->all(), |
||
58 | 'withErrors' => $exception->errors(), |
||
59 | ]); |
||
60 | } elseif ($exception instanceof ValidationException) { |
||
61 | return intend([ |
||
62 | 'back' => true, |
||
63 | 'withInput' => $request->all(), |
||
64 | 'withErrors' => $exception->errors(), |
||
65 | ]); |
||
66 | } elseif ($exception instanceof GenericException) { |
||
67 | return intend([ |
||
68 | 'url' => $exception->getRedirection() ?? route("{$accessarea}.home"), |
||
69 | 'withInput' => $exception->getInputs() ?? $request->all(), |
||
70 | 'with' => ['warning' => $exception->getMessage()], |
||
71 | ]); |
||
72 | } elseif ($exception instanceof AuthorizationException) { |
||
73 | return intend([ |
||
74 | 'url' => in_array($accessarea, ['tenantarea', 'managerarea']) ? route('tenantarea.home') : route('frontarea.home'), |
||
75 | 'with' => ['warning' => $exception->getMessage()], |
||
76 | ]); |
||
77 | } elseif ($exception instanceof NotFoundHttpException) { |
||
78 | // Catch localized routes with missing {locale} |
||
79 | // and redirect them to the correct localized version |
||
80 | if (config('cortex.foundation.route.locale_redirect')) { |
||
81 | $originalUrl = $request->url(); |
||
82 | |||
83 | try { |
||
84 | $localizedUrl = app('laravellocalization')->getLocalizedURL(null, $originalUrl); |
||
85 | |||
86 | // Will return `NotFoundHttpException` exception if no match found! |
||
87 | app('router')->getRoutes()->match(request()->create($localizedUrl)); |
||
88 | |||
89 | return intend([ |
||
90 | 'url' => $originalUrl !== $localizedUrl ? $localizedUrl : route("{$accessarea}.home"), |
||
91 | 'with' => ['warning' => $exception->getMessage()], |
||
92 | ]); |
||
93 | } catch (Exception $exception) { |
||
94 | } |
||
95 | } |
||
96 | |||
97 | return $this->prepareResponse($request, $exception); |
||
98 | } elseif ($exception instanceof ModelNotFoundException) { |
||
99 | $model = $exception->getModel(); |
||
100 | $single = mb_strtolower(mb_substr($model, mb_strrpos($model, '\\') + 1)); |
||
101 | $plural = str_plural($single); |
||
102 | |||
103 | return intend([ |
||
104 | 'url' => $model ? route("{$accessarea}.{$plural}.index") : route("{$accessarea}.home"), |
||
105 | 'with' => ['warning' => trans('cortex/foundation::messages.resource_not_found', ['resource' => $single, 'identifier' => $request->route($single)])], |
||
106 | ]); |
||
107 | } |
||
108 | |||
109 | return parent::render($request, $exception); |
||
110 | } |
||
111 | |||
146 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.