HasLinks::getLinkUrl()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
namespace EventStore\StreamFeed;
3
4
/**
5
 * Class HasLinks
6
 * @package EventStore\StreamFeed
7
 */
8
trait HasLinks
9
{
10
    /**
11
     * @return array
12
     */
13
    abstract protected function getLinks();
14
15
    /**
16
     * @param  LinkRelation $relation
17
     * @return null|string
18
     */
19 17
    public function getLinkUrl(LinkRelation $relation)
20
    {
21 17
        $links = $this->getLinks();
22
23 17
        foreach ($links as $link) {
24 17
            if ($link['relation'] == $relation->toNative()) {
25 17
                return $link['uri'];
26
            }
27
        }
28
29 6
        return null;
30
    }
31
32
    /**
33
     * @param  LinkRelation $relation
34
     * @return boolean
35
     */
36 8
    public function hasLink(LinkRelation $relation)
37
    {
38 8
        return $this->getLinkUrl($relation) !== null;
39
    }
40
}
41