Completed
Branch 1.x (112be9)
by Akihito
06:58 queued 04:37
created

AssistedResourceParam::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the BEAR.Resource package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Resource;
8
9
use BEAR\Resource\Annotation\ResourceParam;
10
use Ray\Di\InjectorInterface;
11
12
final class AssistedResourceParam implements ParamInterface
13
{
14
    private $resourceParam;
15
16 3
    public function __construct(ResourceParam $resourceParam)
17
    {
18 3
        $this->resourceParam = $resourceParam;
19 3
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 3
    public function __invoke($varName, array $query, InjectorInterface $injector)
0 ignored issues
show
Unused Code introduced by
The method parameter $varName is never used
Loading history...
25
    {
26 3
        $resource = $injector->getInstance(ResourceInterface::class);
27 3
        $uri = $this->resourceParam->templated === true ? uri_template($this->resourceParam->uri, $query) : $this->resourceParam->uri;
28 3
        $resourceResult = $resource->get->uri($uri)->eager->request();
29 3
        $fragment = parse_url($uri, PHP_URL_FRAGMENT);
30
31 3
        return $resourceResult[$fragment];
32
    }
33
}
34