Issues (40)

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

1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class LocaleMiddleware
9
{
10
    protected $languages = ['en', 'nl'];
11
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure  $next
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        if (Auth::check()) {
22
            $lang = Auth::user()->preferences['language'];
0 ignored issues
show
Accessing preferences on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
23
24
            app()->setLocale($lang);
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

24
            app()->/** @scrutinizer ignore-call */ setLocale($lang);
Loading history...
25
        } else {
26
            app()->setLocale(env('APP_LOCALE'));
27
        }
28
29
        return $next($request);
30
    }
31
}
32