AriasBros /
eloquent-locale
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Locale\Http\Middleware; |
||||
| 4 | |||||
| 5 | use Closure; |
||||
| 6 | use Locale\Models\Locale; |
||||
| 7 | |||||
| 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) |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | { |
||||
| 20 | $locale = $this->parseLocale($request->header("Accept-Language")); |
||||
| 21 | |||||
| 22 | if ($locale !== null && !app()->isLocale($locale)) { |
||||
|
0 ignored issues
–
show
The method
isLocale() 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
Loading history...
|
|||||
| 23 | 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
Loading history...
|
|||||
| 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) |
||||
| 49 | { |
||||
| 50 | return Locale::whereKey($locale)->count() > 0; |
||||
| 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.