Conditions | 10 |
Paths | 10 |
Total Lines | 38 |
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 |
||
20 | public function handle($request, Closure $next) |
||
21 | { |
||
22 | // If the URL of the request is in exceptions. |
||
23 | if ($this->shouldIgnore($request)) { |
||
24 | return $next($request); |
||
25 | } |
||
26 | |||
27 | $params = explode('/', $request->path()); |
||
28 | $locale = session('locale', false); |
||
29 | |||
30 | if (\count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) { |
||
31 | session(['locale' => $params[0]]); |
||
32 | |||
33 | return $next($request); |
||
34 | } |
||
35 | elseif(empty($locale) && app('laravellocalization')->hideUrlAndAcceptHeader()){ |
||
36 | // When default locale is hidden and accept language header is true, |
||
37 | // then compute browser language when no session has been set. |
||
38 | // Once the session has been set, there is no need |
||
39 | // to negotiate language from browser again. |
||
40 | $negotiator = new LanguageNegotiator(app('laravellocalization')->getDefaultLocale(), app('laravellocalization')->getSupportedLocales(), $request); |
||
41 | $locale = $negotiator->negotiateLanguage(); |
||
42 | session(['locale' => $locale]); |
||
43 | } |
||
44 | |||
45 | if($locale === false){ |
||
46 | $locale = app('laravellocalization')->getCurrentLocale(); |
||
47 | } |
||
48 | |||
49 | if ($locale && app('laravellocalization')->checkLocaleInSupportedLocales($locale) && !(app('laravellocalization')->isHiddenDefault($locale))) { |
||
50 | app('session')->reflash(); |
||
51 | $redirection = app('laravellocalization')->getLocalizedURL($locale); |
||
52 | |||
53 | return new RedirectResponse($redirection, 302, ['Vary' => 'Accept-Language']); |
||
54 | } |
||
55 | |||
56 | return $next($request); |
||
57 | } |
||
58 | } |
||
59 |