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

AssistedResourceParam::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
crap 2
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