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   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 38 10
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