Completed
Push — develop ( 7322c5...3524a4 )
by Michiel
17s queued 11s
created

AttributeAggregationAttribute::getUserNameId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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 int
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     */
33
    private $userId;
34
35
    /**
36
     * @var string
37
     */
38
    private $accountType;
39
40
    /**
41
     * @var string
42
     */
43
    private $linkedId;
44
45
    /**
46
     * @var string
47
     */
48
    private $logoPath;
49
50
    /**
51
     * @var string
52
     */
53
    private $connectUrl;
54
55
    /**
56
     * @var bool
57
     */
58
    private $isConnected = false;
59
60
    /**
61
     * @param int $id
62
     * @param string $userId
63
     * @param string $accountType
64
     * @param string $linkedId
65
     * @param string $logoPath
66
     * @param string $connectUrl
67
     * @param bool $isConnected
68
     */
69
    public function __construct(
70
        $id,
71
        $userId,
72
        $accountType,
73
        $linkedId,
74
        $logoPath,
75
        $connectUrl,
76
        $isConnected
77
    ) {
78
        $this->id = $id;
79
        $this->userId = $userId;
80
        $this->accountType = $accountType;
81
        $this->linkedId = $linkedId;
82
        $this->logoPath = $logoPath;
83
        $this->connectUrl = $connectUrl;
84
        $this->isConnected = $isConnected;
85
    }
86
87
    public static function fromConfig(
88
        AttributeAggregationAttributeConfiguration $enabledAttribute,
89
        $isConnected,
90
        $id,
91
        $userId,
92
        $linkedId = null
93
    ) {
94
        return new self(
95
            $id,
96
            $userId,
97
            $enabledAttribute->getAccountType(),
98
            $linkedId,
99
            $enabledAttribute->getLogoPath(),
100
            $enabledAttribute->getConnectUrl(),
101
            $isConnected
102
        );
103
    }
104
105
    public static function fromApiResponse(array $attributeData)
106
    {
107
        Assertion::keyExists($attributeData, 'id', 'No id found on attribute');
108
        Assertion::integer($attributeData['id'], 'Id should be integer');
109
110
        Assertion::keyExists($attributeData, 'urn', 'No userId name id found on attribute');
111
        Assertion::string($attributeData['urn'], 'userId name id Id should be a string');
112
113
        Assertion::keyExists($attributeData, 'accountType', 'No account type found on attribute');
114
        Assertion::string($attributeData['accountType'], 'Account type should be a string');
115
116
        Assertion::keyExists($attributeData, 'linkedId', 'No linked id found on attribute');
117
        Assertion::string($attributeData['linkedId'], 'Linked id should be a string');
118
119
        return new self(
120
            $attributeData['id'],
121
            $attributeData['urn'],
122
            $attributeData['accountType'],
123
            $attributeData['linkedId'],
124
            '',
125
            '',
126
            '',
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
            true
0 ignored issues
show
Unused Code introduced by
The call to AttributeAggregationAttribute::__construct() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
128
        );
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getAccountType()
135
    {
136
        return $this->accountType;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getLinkedId()
143
    {
144
        return $this->linkedId;
145
    }
146
147
    /**
148
     * @return string
149
     */
150
    public function getLogoPath()
151
    {
152
        return $this->logoPath;
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function getConnectUrl()
159
    {
160
        return $this->connectUrl;
161
    }
162
163
    /**
164
     * @return bool
165
     */
166
    public function isConnected()
167
    {
168
        return $this->isConnected;
169
    }
170
171
    /**
172
     * @return int
173
     */
174
    public function getId()
175
    {
176
        return $this->id;
177
    }
178
179
    public function getUserNameId()
180
    {
181
        return $this->userId;
182
    }
183
}
184