Completed
Push — master ( e0250b...fc23d8 )
by Tomas
02:44
created

ApiLink   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 2
c 4
b 1
f 2
lcom 1
cbo 2
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A link() 0 9 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 15
    public function __construct(LinkGenerator $linkGenerator)
21
    {
22 15
        $this->linkGenerator = $linkGenerator;
23 15
    }
24
25
    /**
26
     * Create link to specified api endpoint
27
     *
28
     * @param EndpointIdentifier  $endpoint
29
     * @param array               $params
30
     *
31
     * @return string
32
     */
33 6
    public function link(EndpointIdentifier $endpoint, $params = [])
34
    {
35 6
        $params = array_merge([
36 6
            'version' => $endpoint->getVersion(),
37 6
            'package' => $endpoint->getPackage(),
38 6
            'apiAction' => $endpoint->getApiAction()
39 6
        ], $params);
40 6
        return $this->linkGenerator->link('Api:Api:default', $params);
41
    }
42
}
43