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.
Completed
Pull Request — master (#384)
by Cretu
01:52
created

LocaleSessionRedirect   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 20 7
1
<?php
2
3
namespace Mcamara\LaravelLocalization\Middleware;
4
5
use Closure;
6
use Illuminate\Http\RedirectResponse;
7
8
class LocaleSessionRedirect
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param \Closure                 $next
15
     *
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $params = explode('/', $request->path());
21
        $locale = session('locale', false);
22
23
        if (count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
24
            session(['locale' => $params[0]]);
25
26
            return $next($request);
27
        }
28
29
        if ($locale && app('laravellocalization')->checkLocaleInSupportedLocales($locale) && !(app('laravellocalization')->getDefaultLocale() === $locale && app('laravellocalization')->hideDefaultLocaleInURL())) {
30
            app('session')->reflash();
31
            $redirection = app('laravellocalization')->getLocalizedURL($locale);
32
33
            return new RedirectResponse($redirection, 302, ['Vary' => 'Accept-Language']);
34
        }
35
36
        return $next($request);
37
    }
38
}
39