Test Failed
Pull Request — master (#122)
by
unknown
30:03 queued 23:05
created

QueryDetector::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 2
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Locale\Detectors;
4
5
use Illuminate\Http\Request;
6
use Thinktomorrow\Locale\Scope;
7
use Thinktomorrow\Locale\Values\Config;
8
use Thinktomorrow\Locale\Values\Locale;
9
10
class QueryDetector implements Detector
11
{
12
    /**
13
     * @var Request
14
     */
15
    private $request;
16
17
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
18
    {
19
        $this->request = $request;
20
    }
21
22
    public function get(Scope $scope, Config $config): ?Locale
23
    {
24
        if (!isset($config['query_key'])) {
25
            return null;
26
        }
27
28
        if (!$queryValue = $this->request->get($config['query_key'])) {
29
            return null;
30
        }
31
32
        return ($scope->validateLocale(Locale::from($queryValue))) ? Locale::from($queryValue) : null;
33
    }
34
}
35