LocalePreferredUserLanguage::match()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 3
rs 10
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