LocaleMiddleware::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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
Bug introduced by
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
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

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