Completed
Pull Request — develop (#82)
by
unknown
01:47
created

AttributeAggregationAttribute::fromApiResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\Profile\Value\AttributeAggregation;
20
21
use Assert\Assertion;
22
23
final class AttributeAggregationAttribute
24
{
25
    /**
26
     * @var string
27
     */
28
    private $identifier;
29
30
    /**
31
     * @var string
32
     */
33
    private $values;
34
35
    /**
36
     * @var string
37
     */
38
    private $source;
39
40
    /**
41
     * @var string
42
     */
43
    private $logoPath;
44
45
    /**
46
     * @var string
47
     */
48
    private $connectUrl;
49
50
    /**
51
     * @var string
52
     */
53
    private $disconnectUrl;
54
55
    /**
56
     * @var bool
57
     */
58
    private $isConnected = false;
59
60
    /**
61
     * @param string $identifier
62
     * @param string $logoPath
63
     * @param string $connectUrl
64
     * @param string $disconnectUrl
65
     * @param bool $isConnected
66
     */
67
    public function __construct($identifier, $logoPath, $connectUrl, $disconnectUrl, $isConnected)
68
    {
69
        $this->identifier = $identifier;
70
        $this->logoPath = $logoPath;
71
        $this->connectUrl = $connectUrl;
72
        $this->disconnectUrl = $disconnectUrl;
73
        $this->isConnected = $isConnected;
74
    }
75
76
    public static function fromConfig(AttributeAggregationAttributeConfiguration $enabledAttribute, $isConnected)
77
    {
78
        return new self(
79
            $enabledAttribute->getIdentifier(),
80
            $enabledAttribute->getLogoPath(),
81
            $enabledAttribute->getConnectUrl(),
82
            $enabledAttribute->getDisconnectUrl(),
83
            $isConnected
84
        );
85
    }
86
87
    public static function fromApiResponse(array $attributeData)
88
    {
89
        Assertion::keyExists($attributeData, 'name', 'The name should be set on the attribute');
90
        Assertion::string($attributeData['name'], 'The name should be a string');
91
        Assertion::keyExists($attributeData, 'values', 'The values should be set on the attribute');
92
        Assertion::isArray($attributeData['values'], 'The values should be an array');
93
        Assertion::keyExists($attributeData, 'source', 'The source should be set on the attribute');
94
        Assertion::string($attributeData['source'], 'The source should be a string');
95
96
        $attribute = new self(
97
            $attributeData['name'],
98
            '',
99
            '',
100
            '',
101
            true
102
        );
103
        $attribute->values = $attributeData['values'];
104
        $attribute->source = $attributeData['source'];
105
        return $attribute;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getIdentifier()
112
    {
113
        return $this->identifier;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getLogoPath()
120
    {
121
        return $this->logoPath;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getConnectUrl()
128
    {
129
        return $this->connectUrl;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getDisconnectUrl()
136
    {
137
        return $this->disconnectUrl;
138
    }
139
140
    /**
141
     * @return bool
142
     */
143
    public function isConnected()
144
    {
145
        return $this->isConnected;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getValues()
152
    {
153
        return $this->values;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getSource()
160
    {
161
        return $this->source;
162
    }
163
}
164