IndexedEndpoint::isDefault()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OpenConext\Value\Saml\Metadata\Common;
4
5
use OpenConext\Value\Assert\Assertion;
6
use OpenConext\Value\Serializable;
7
8
final class IndexedEndpoint implements Serializable
9
{
10
    /**
11
     * @var Endpoint
12
     */
13
    private $endpoint;
14
15
    /**
16
     * @var int
17
     */
18
    private $index;
19
20
    /**
21
     * @var bool
22
     */
23
    private $isDefault;
24
25
    public function __construct(Endpoint $endpoint, $index, $isDefault = false)
26
    {
27
        Assertion::integer($index);
28
        Assertion::boolean($isDefault);
29
30
        $this->endpoint = $endpoint;
31
        $this->index = $index;
32
        $this->isDefault = $isDefault;
33
    }
34
35
    /**
36
     * @return Binding
37
     */
38
    public function getBinding()
39
    {
40
        return $this->endpoint->getBinding();
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getLocation()
47
    {
48
        return $this->endpoint->getLocation();
49
    }
50
51
    /**
52
     * @return null|string
53
     */
54
    public function getResponseLocation()
55
    {
56
        return $this->endpoint->getResponseLocation();
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getIndex()
63
    {
64
        return $this->index;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isDefault()
71
    {
72
        return $this->isDefault;
73
    }
74
75
    /**
76
     * @param IndexedEndpoint $other
77
     * @return bool 
78
     */
79
    public function equals(IndexedEndpoint $other)
80
    {
81
        return $this->endpoint->equals($other->endpoint)
82
                && $this->index === $other->index
83
                && $this->isDefault === $other->isDefault;
84
    }
85
86
    public static function deserialize($data)
87
    {
88
        Assertion::isArray($data);
89
        Assertion::keysExist($data, array('endpoint', 'index', 'is_default'));
90
91
        return new self(
92
            Endpoint::deserialize($data['endpoint']),
93
            $data['index'],
94
            $data['is_default']
95
        );
96
    }
97
98
    public function serialize()
99
    {
100
        return array(
101
            'endpoint' => $this->endpoint->serialize(),
102
            'index' => $this->index,
103
            'is_default' => $this->isDefault
104
        );
105
    }
106
107
    public function __toString()
108
    {
109
        return sprintf(
110
            'IndexedEndpoint(%s, index=%d, isDefault=%s',
111
            (string) $this->endpoint,
112
            $this->index,
113
            ($this->isDefault ? 'true' : 'false')
114
        );
115
    }
116
}
117