Completed
Push — 1.x ( d468cb...112be9 )
by Akihito
02:57
created

AssistedResourceParam   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 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