Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class AcceptLanguage |
||
9 | { |
||
10 | /** |
||
11 | * Set the locale to use in the API. |
||
12 | * |
||
13 | * @param \Illuminate\Http\Request $request |
||
14 | * @param \Closure $next |
||
15 | * @param string|null $guard |
||
16 | * @return mixed |
||
17 | */ |
||
18 | public function handle($request, Closure $next, $guard = null) |
||
|
|||
19 | { |
||
20 | $locale = $this->parseLocale($request->header("Accept-Language")); |
||
21 | |||
22 | if ($locale !== null && !app()->isLocale($locale)) { |
||
23 | app()->setLocale($locale); |
||
24 | } |
||
25 | |||
26 | return $next($request); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @since 1.0.0 |
||
31 | * @param string $locale |
||
32 | * @return string |
||
33 | */ |
||
34 | protected function parseLocale($locale) |
||
35 | { |
||
36 | $locale = explode(",", preg_replace("/\;q=\d.\d/", "", $locale)); |
||
37 | |||
38 | return collect($locale)->first(function ($locale) { |
||
39 | return $this->isLocaleSupported($locale); |
||
40 | }); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @since 1.0.0 |
||
45 | * @param string $locale |
||
46 | * @return bool |
||
47 | */ |
||
48 | protected function isLocaleSupported($locale) |
||
51 | } |
||
52 | } |
||
53 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.