EventStreamFeedLink::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace RayRutjes\GetEventStore\Client\Http\Feed;
4
5
class EventStreamFeedLink
6
{
7
    const LINK_SELF = 'self';
8
    const LINK_FIRST = 'first';
9
    const LINK_LAST = 'last';
10
    const LINK_PREVIOUS = 'previous';
11
    const LINK_NEXT = 'next';
12
    const LINK_METADATA = 'metadata';
13
14
    /**
15
     * @var array
16
     */
17
    private $validRelations = [self::LINK_SELF, self::LINK_FIRST, self::LINK_LAST, self::LINK_PREVIOUS, self::LINK_NEXT, self::LINK_METADATA];
18
19
    /**
20
     * @var string
21
     */
22
    private $uri;
23
24
    /**
25
     * @var string
26
     */
27
    private $relation;
28
29
    /**
30
     * @param string $uri
31
     * @param string $relation
32
     */
33
    public function __construct(string $uri, string $relation)
34
    {
35
        if (!in_array($relation, $this->validRelations)) {
36
            throw new \InvalidArgumentException(sprintf('Invalid link relation %s.', $relation));
37
        }
38
        $this->uri = $uri;
39
        $this->relation = $relation;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getUri(): string
46
    {
47
        return $this->uri;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getRelation(): string
54
    {
55
        return $this->relation;
56
    }
57
}
58