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

ScriptLocalization   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getVariable() 0 3 1
A shouldBeLoaded() 0 3 1
A getHandle() 0 3 1
A getData() 0 3 1
A __construct() 0 11 1
A getPolicy() 0 3 1
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