Issues (61)

app/Http/Middleware/PreferLanguageMiddleware.php (2 issues)

Severity
1
<?php
2
3
namespace Gameap\Http\Middleware;
4
5
use Illuminate\Http\Request;
6
use Closure;
7
8
class PreferLanguageMiddleware
9
{
10
    public function handle(Request $request, Closure $next)
11
    {
12
        if (!extension_loaded('intl') || app()->getLocale() != '') {
0 ignored issues
show
The method getLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
        if (!extension_loaded('intl') || app()->/** @scrutinizer ignore-call */ getLocale() != '') {
Loading history...
13
            return $next($request);
14
        }
15
16
        $headerValue = $request->server('HTTP_ACCEPT_LANGUAGE');
17
        if ($headerValue !== null && !is_array($headerValue) && $headerValue !== "") {
18
            $locale = \Locale::acceptFromHttp($headerValue);
19
20
            if ($locale !== false && $locale !== "") {
21
                $locale = substr($locale, 0, 2);
22
                app()->setLocale($locale);
0 ignored issues
show
The method setLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
                app()->/** @scrutinizer ignore-call */ setLocale($locale);
Loading history...
23
            }
24
        }
25
26
27
        return $next($request);
28
    }
29
}
30