Test Failed
Push — master ( 8a7ae2...79eb97 )
by Chris
06:09
created

ScriptLocalization::getConstraints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Leonidas\Library\Core\Asset;
4
5
use Leonidas\Contracts\Http\ServerRequestPolicyInterface;
6
use Leonidas\Contracts\Ui\Asset\ScriptLocalizationInterface;
7
use Leonidas\Library\Core\Http\Policies\NoPolicy;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class ScriptLocalization implements ScriptLocalizationInterface
11
{
12
    protected string $handle;
13
14
    protected string $variable;
15
16
    protected array $data;
17
18
    protected ?ServerRequestPolicyInterface $policy = null;
19
20
    public function __construct(
21
        string $handle,
22
        string $variable,
23
        array $data,
24
        ?ServerRequestPolicyInterface $policy
25
    ) {
26
        $this->handle = $handle;
27
        $this->variable = $variable;
28
        $this->data = $data;
29
30
        $this->policy = $policy ?? new NoPolicy();
31
    }
32
33
    public function getHandle(): string
34
    {
35
        return $this->handle;
36
    }
37
38
    public function getVariable(): string
39
    {
40
        return $this->variable;
41
    }
42
43
    public function getData(): array
44
    {
45
        return $this->data;
46
    }
47
48
    public function getPolicy(): ?ServerRequestPolicyInterface
49
    {
50
        return $this->policy;
51
    }
52
53
    public function shouldBeLoaded(ServerRequestInterface $request): bool
54
    {
55
        return $this->policy->approvesRequest($request);
0 ignored issues
show
Bug introduced by
The method approvesRequest() does not exist on null. ( Ignorable by Annotation )

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

55
        return $this->policy->/** @scrutinizer ignore-call */ approvesRequest($request);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
    }
57
}
58