LocaleInPreferredBrowserLanguage::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
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 mindtwo\LaravelMultilingual\Services\Locale;
7
8
class LocaleInPreferredBrowserLanguage implements LocaleDetector
9
{
10
    /**
11
     * @param Request $request
12
     * @param Locale  $locale
13
     *
14
     * @return bool
15
     */
16
    public function match(Request $request, Locale $locale): bool
17
    {
18
        return ! empty($this->detectPreferredLanguage());
0 ignored issues
show
Bug introduced by
The call to mindtwo\LaravelMultiling...tectPreferredLanguage() has too few arguments starting with request. ( Ignorable by Annotation )

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

18
        return ! empty($this->/** @scrutinizer ignore-call */ detectPreferredLanguage());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
19
    }
20
21
    /**
22
     * @param Request $request
23
     * @param Locale  $locale
24
     *
25
     * @return string
26
     */
27
    public function get(Request $request, Locale $locale): string
28
    {
29
        return $this->detectPreferredLanguage();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->detectPreferredLanguage() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
Bug introduced by
The call to mindtwo\LaravelMultiling...tectPreferredLanguage() has too few arguments starting with request. ( Ignorable by Annotation )

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

29
        return $this->/** @scrutinizer ignore-call */ detectPreferredLanguage();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
30
    }
31
32
    /**
33
     * @param Request $request
34
     * @param Locale  $locale
35
     *
36
     * @return string
37
     */
38
    public function detectPreferredLanguage(Request $request, Locale $locale): string
39
    {
40
        return $request->getPreferredLanguage($locale->available->toArray());
0 ignored issues
show
Bug Best Practice introduced by
The property available does not exist on mindtwo\LaravelMultilingual\Services\Locale. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The expression return $request->getPref...->available->toArray()) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
41
    }
42
}
43