Test Setup Failed
Push — develop ( 6f7221...94b6b4 )
by Nikita
06:49
created

PreferLanguageMiddleware::handle()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 18
rs 8.8333
cc 7
nc 4
nop 2
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')) {
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