Links   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 53.33%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 42
wmc 7
lcom 1
cbo 1
ccs 8
cts 15
cp 0.5333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A getLink() 0 8 2
A __get() 0 11 2
1
<?php
2
namespace ApigilityClient\Resource;
3
4
use ApigilityClient\Exception\UnexpectedValueException;
5
6
final class Links
7
{
8
9
    const FIRST_PAGE   = 'first';
10
    const NEXT_PAGE    = 'next';
11
    const CURRENT_PAGE = 'self';
12
    const LAST_PAGE    = 'last';
13
14
    /**
15
     * @var Array
16
     */
17
    private $links = array();
18
19 3
    public function __construct(array $links)
20
    {
21 3
        if (! empty($links)) foreach ($links as $key => $val) {
22 3
            $this->links[$key] = $val->getHref();
23 3
        }
24 3
    }
25
26 1
    public function getLink($rel = self::CURRENT_PAGE)
27
    {
28 1
        if (isset($this->links[$rel])) {
29 1
            return $this->links[$rel];
30
        }
31
32
        return '';
33
    }
34
35
    public function __get($rel)
36
    {
37
        if (! isset($this->links[$rel])) {
38
            throw new UnexpectedValueException(sprintf(
39
                'Link "%s" não existe',
40
                $rel
41
            ));
42
        }
43
44
        return $this->links[$rel];
45
    }
46
47
}
48