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
Push — master ( 5a4e01...d07e87 )
by Marc
8s
created

LocaleCookieRedirect::handle()   C

Complexity

Conditions 8
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 6.6037
cc 8
eloc 12
nc 4
nop 2
1
<?php namespace Mcamara\LaravelLocalization\Middleware;
2
3
use Illuminate\Http\RedirectResponse;
4
use Closure;
5
6
class LocaleCookieRedirect extends LaravelLocalizationMiddlewareBase 
7
{
8
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param  \Illuminate\Http\Request $request
13
     * @param  \Closure $next
14
     *
15
     * @return mixed
16
     */
17
     public function handle($request, Closure $next) {
18
         // If the URL of the request is in exceptions.
19
         if ($this->shouldIgnore($request)) {
20
             return $next($request);
21
         }
22
23
         $params = explode('/', $request->path());
24
         $locale = $request->cookie('locale', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
26
         if (count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
27
            return $next($request)->withCookie(cookie()->forever('locale', $params[0]));
0 ignored issues
show
Bug introduced by
The method forever() does not seem to exist on object<Symfony\Component\HttpFoundation\Cookie>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
         }
29
30
         if ($locale && app('laravellocalization')->checkLocaleInSupportedLocales($locale) && !(app('laravellocalization')->getDefaultLocale() === $locale && app('laravellocalization')->hideDefaultLocaleInURL())) {
31
           $redirection = app('laravellocalization')->getLocalizedURL($locale);
32
           $redirectResponse = new RedirectResponse($redirection, 302, ['Vary' => 'Accept-Language']);
33
34
           return $redirectResponse->withCookie(cookie()->forever('locale', $params[0]));
0 ignored issues
show
Bug introduced by
The method forever() does not seem to exist on object<Symfony\Component\HttpFoundation\Cookie>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
         }
36
37
         return $next($request);
38
     }
39
}
40