PreferLanguageMiddleware   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 10
c 1
b 0
f 1
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 18 8
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
introduced by
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
introduced by
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