Links::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 3
eloc 3
c 3
b 1
f 0
nc 3
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
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