LocalePreferredUserLanguage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A match() 0 3 2
1
<?php
2
3
namespace mindtwo\LaravelMultilingual\Http\Middleware\LocaleDetectors;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use mindtwo\LaravelMultilingual\Services\Locale;
8
9
class LocalePreferredUserLanguage implements LocaleDetector
10
{
11
    /**
12
     * @param Request $request
13
     * @param Locale  $locale
14
     *
15
     * @return bool
16
     */
17
    public function match(Request $request, Locale $locale): bool
18
    {
19
        return Auth::user() && is_callable([Auth::user(), 'preferredLocale']);
20
    }
21
22
    /**
23
     * @param Request $request
24
     * @param Locale  $locale
25
     *
26
     * @return string
27
     */
28
    public function get(Request $request, Locale $locale): string
29
    {
30
        return Auth::user()->preferredLocale();
0 ignored issues
show
Bug introduced by
The method preferredLocale() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return Auth::user()->/** @scrutinizer ignore-call */ preferredLocale();
Loading history...
31
    }
32
}
33