AbstractInlineAsset::shouldBeLoaded()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Leonidas\Library\Core\Asset;
4
5
use Leonidas\Library\Core\Http\Policy\NoPolicy;
6
use Psr\Http\Message\ServerRequestInterface;
7
use WebTheory\HttpPolicy\ServerRequestPolicyInterface;
8
9
class AbstractInlineAsset
10
{
11
    protected string $handle;
12
13
    protected string $code;
14
15
    protected ?ServerRequestPolicyInterface $policy = null;
16
17
    public function __construct(string $handle, string $code, ?ServerRequestPolicyInterface $policy = null)
18
    {
19
        $this->handle = $handle;
20
        $this->code = $code;
21
22
        $this->policy = $policy ?? new NoPolicy();
23
    }
24
25
    public function getHandle(): string
26
    {
27
        return $this->handle;
28
    }
29
30
    public function getCode(): string
31
    {
32
        return $this->code;
33
    }
34
35
    public function getPolicy(): ServerRequestPolicyInterface
36
    {
37
        return $this->policy;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->policy could return the type null which is incompatible with the type-hinted return WebTheory\HttpPolicy\ServerRequestPolicyInterface. Consider adding an additional type-check to rule them out.
Loading history...
38
    }
39
40
    public function shouldBeLoaded(ServerRequestInterface $request): bool
41
    {
42
        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

42
        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...
43
    }
44
}
45