AbstractInlineAsset   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 34
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 1
wmc 5

5 Methods

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