Completed
Push — master ( 09c4bf...21aaac )
by
unknown
08:14
created

SetLocale   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 3
1
<?php
2
3
namespace BBSLab\NovaTranslation\Http\Middleware;
4
5
use BBSLab\NovaTranslation\Models\Locale;
6
use Illuminate\Support\Facades\Session;
7
8
class SetLocale
9
{
10
    /**
11
     * Handle the incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function handle($request, $next)
18
    {
19
        if (Session::has('nova_locale')) {
20
            $locale = Session::get('nova_locale');
21
        } else {
22
            $browserLocale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
23
            $databaseLocale = Locale::query()->select('id')->where('iso', '=', $browserLocale)->first();
0 ignored issues
show
Bug introduced by
The method select() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean createSelectWithConstraint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
24
            if (! empty($databaseLocale)) {
25
                $locale = $browserLocale;
26
            } else {
27
                $locale = config('app.locale');
28
            }
29
            Session::put('nova_locale', $locale);
30
        }
31
32
        app()->setLocale($locale);
33
34
        return $next($request);
35
    }
36
}
37