Passed
Push — 1.x ( 90de9d...e2e7a5 )
by Akihito
05:28 queued 03:04
created

AssistedResourceParam   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use BEAR\Resource\Annotation\ResourceParam;
8
use Override;
9
use Ray\Di\InjectorInterface;
10
11
use function parse_url;
12
use function uri_template;
13
14 3
use const PHP_URL_FRAGMENT;
15
16 3
final readonly class AssistedResourceParam implements ParamInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 16 at column 6
Loading history...
17 3
{
18
    public function __construct(
19
        private ResourceParam $resourceParam,
20
    ) {
21
    }
22 3
23
    /**
24 3
     * {@inheritDoc}
25 3
     */
26 3
    #[Override]
27 3
    public function __invoke(string $varName, array $query, InjectorInterface $injector)
28 3
    {
29
        unset($varName);
30 3
        $resource = $injector->getInstance(ResourceInterface::class);
31
        $uri = $this->resourceParam->templated === true ? uri_template($this->resourceParam->uri, $query) : $this->resourceParam->uri;
32
        $resourceResult = $resource->uri($uri)();
33
        $fragment = (string) parse_url($uri, PHP_URL_FRAGMENT);
34
35
        return $resourceResult[$fragment];
36
    }
37
}
38