QueryDetector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 12 4
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 72
    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 72
        $this->request = $request;
20 72
    }
21
22 72
    public function get(Scope $scope, Config $config): ?Locale
23
    {
24 72
        if (!isset($config['query_key'])) {
25 1
            return null;
26
        }
27
28 71
        if (!$queryValue = $this->request->get($config['query_key'])) {
29 69
            return null;
30
        }
31
32 3
        return ($scope->validateLocale(Locale::from($queryValue))) ? Locale::from($queryValue) : null;
33
    }
34
}
35