Completed
Push — master ( fcda7e...e0250b )
by Tomas
02:45
created

ApiLink::__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 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Tomaj\NetteApi\Link;
4
5
use Nette\Application\LinkGenerator;
6
use Tomaj\NetteApi\EndpointIdentifier;
7
8
class ApiLink
9
{
10
    /**
11
     * @var LinkGenerator
12
     */
13
    private $linkGenerator;
14
15
    /**
16
     * Create ApiLink
17
     *
18
     * @param LinkGenerator $linkGenerator
19
     */
20 9
    public function __construct(LinkGenerator $linkGenerator)
21
    {
22 9
        $this->linkGenerator = $linkGenerator;
23 9
    }
24
25
    /**
26
     * Create link to specified api endpoint
27
     *
28
     * @param EndpointIdentifier  $endpoint
29
     * @param array               $params
30
     *
31
     * @return string
32
     */
33
    public function link(EndpointIdentifier $endpoint, $params = [])
34
    {
35
        $params = array_merge([
36
            'version' => $endpoint->getVersion(),
37
            'package' => $endpoint->getPackage(),
38
            'apiAction' => $endpoint->getApiAction()
39
        ], $params);
40
        return $this->linkGenerator->link('Api:Api:default', $params);
41
    }
42
}
43