Completed
Push — master ( 9e89d5...89e339 )
by Tomas
11:24
created

ApiLink::link()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6667
cc 1
eloc 7
nc 1
nop 2
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 12
    public function __construct(LinkGenerator $linkGenerator)
21
    {
22 12
        $this->linkGenerator = $linkGenerator;
23 12
    }
24
25
    /**
26
     * Create link to specified api endpoint
27
     *
28
     * @param EndpointIdentifier  $endpoint
29
     * @param array               $params
30
     *
31
     * @return string
32
     */
33 3
    public function link(EndpointIdentifier $endpoint, $params = [])
34
    {
35 3
        $params = array_merge([
36 3
            'version' => $endpoint->getVersion(),
37 3
            'package' => $endpoint->getPackage(),
38 3
            'apiAction' => $endpoint->getApiAction()
39 3
        ], $params);
40 3
        return $this->linkGenerator->link('Api:Api:default', $params);
41
    }
42
}
43