GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LocaleSessionRedirect::handle()   B
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 7.6666
c 0
b 0
f 0
cc 10
nc 10
nop 2

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
namespace Mcamara\LaravelLocalization\Middleware;
4
5
use Closure;
6
use Illuminate\Http\RedirectResponse;
7
use Mcamara\LaravelLocalization\LanguageNegotiator;
8
use Mcamara\LaravelLocalization\LaravelLocalization;
9
10
class LocaleSessionRedirect extends LaravelLocalizationMiddlewareBase
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param \Closure                 $next
17
     *
18
     * @return mixed
19
     */
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