Completed
Pull Request — develop (#87)
by
unknown
01:51
created

AttributeAggregationAttribute::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 $accountType;
29
30
    /**
31
     * @var string
32
     */
33
    private $linkedId;
34
35
    /**
36
     * @var string
37
     */
38
    private $logoPath;
39
40
    /**
41
     * @var string
42
     */
43
    private $connectUrl;
44
45
    /**
46
     * @var string
47
     */
48
    private $disconnectUrl;
49
50
    /**
51
     * @var bool
52
     */
53
    private $isConnected = false;
54
55
    /**
56
     * @param string $accountType
57
     * @param string $linkedId
58
     * @param string $logoPath
59
     * @param string $connectUrl
60
     * @param string $disconnectUrl
61
     * @param bool $isConnected
62
     */
63
    public function __construct(
64
        $accountType,
65
        $linkedId,
66
        $logoPath,
67
        $connectUrl,
68
        $disconnectUrl,
69
        $isConnected
70
    ) {
71
        $this->accountType = $accountType;
72
        $this->linkedId = $linkedId;
73
        $this->logoPath = $logoPath;
74
        $this->connectUrl = $connectUrl;
75
        $this->disconnectUrl = $disconnectUrl;
76
        $this->isConnected = $isConnected;
77
    }
78
79
    public static function fromConfig(
80
        AttributeAggregationAttributeConfiguration $enabledAttribute,
81
        $isConnected,
82
        $linkedId = null
83
    ) {
84
        return new self(
85
            $enabledAttribute->getAccountType(),
86
            $linkedId,
87
            $enabledAttribute->getLogoPath(),
88
            $enabledAttribute->getConnectUrl(),
89
            $enabledAttribute->getDisconnectUrl(),
90
            $isConnected
91
        );
92
    }
93
94
    public static function fromApiResponse(array $attributeData)
95
    {
96
        Assertion::keyExists($attributeData, 'accountType', 'No account type found on attribute');
97
        Assertion::string($attributeData['accountType'], 'Account type should be a string');
98
99
        Assertion::keyExists($attributeData, 'linkedId', 'No linked id found on attribute');
100
        Assertion::string($attributeData['linkedId'], 'Linked id should be a string');
101
102
        return new self(
103
            $attributeData['accountType'],
104
            $attributeData['linkedId'],
105
            '',
106
            '',
107
            '',
108
            true
109
        );
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getAccountType()
116
    {
117
        return $this->accountType;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getLinkedId()
124
    {
125
        return $this->linkedId;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getLogoPath()
132
    {
133
        return $this->logoPath;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getConnectUrl()
140
    {
141
        return $this->connectUrl;
142
    }
143
144
    /**
145
     * @return string
146
     */
147
    public function getDisconnectUrl()
148
    {
149
        return $this->disconnectUrl;
150
    }
151
152
    /**
153
     * @return bool
154
     */
155
    public function isConnected()
156
    {
157
        return $this->isConnected;
158
    }
159
}
160