1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
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 Surfnet\StepupMiddlewareClient\Identity\Dto; |
20
|
|
|
|
21
|
|
|
use Assert; |
22
|
|
|
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery; |
23
|
|
|
|
24
|
|
|
final class RaSecondFactorSearchQuery implements HttpQuery |
25
|
|
|
{ |
26
|
|
|
const STATUS_UNVERIFIED = 'unverified'; |
27
|
|
|
const STATUS_VERIFIED = 'verified'; |
28
|
|
|
const STATUS_VETTED = 'vetted'; |
29
|
|
|
const STATUS_REVOKED = 'revoked'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $actorInstitution; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private $name; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null |
43
|
|
|
*/ |
44
|
|
|
private $type; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string|null The second factor type's ID (eg. Yubikey public ID) |
48
|
|
|
*/ |
49
|
|
|
private $secondFactorId; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string|null |
53
|
|
|
*/ |
54
|
|
|
private $email; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string|null One of the STATUS_* constants. |
58
|
|
|
*/ |
59
|
|
|
private $status; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string|null |
63
|
|
|
*/ |
64
|
|
|
private $institution; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string|null |
68
|
|
|
*/ |
69
|
|
|
private $orderBy; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var string|null |
73
|
|
|
*/ |
74
|
|
|
private $orderDirection; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var int |
78
|
|
|
*/ |
79
|
|
|
private $pageNumber; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $institution |
83
|
|
|
* @param int $pageNumber |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function __construct($institution, $pageNumber) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$this->assertNonEmptyString($institution, 'institution'); |
88
|
|
|
Assert\that($pageNumber) |
89
|
|
|
->integer('Page number must be an integer') |
90
|
|
|
->min(1, 'Page number must be greater than or equal to 1'); |
91
|
|
|
|
92
|
|
|
$this->actorInstitution = $institution; |
93
|
|
|
$this->pageNumber = $pageNumber; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return null|string |
98
|
|
|
*/ |
99
|
|
|
public function getName() |
100
|
|
|
{ |
101
|
|
|
return $this->name; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param null|string $name |
106
|
|
|
*/ |
107
|
|
|
public function setName($name) |
108
|
|
|
{ |
109
|
|
|
$this->assertNonEmptyString($name, 'name'); |
110
|
|
|
|
111
|
|
|
$this->name = $name; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return null|string |
116
|
|
|
*/ |
117
|
|
|
public function getType() |
118
|
|
|
{ |
119
|
|
|
return $this->type; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param null|string $type |
124
|
|
|
*/ |
125
|
|
|
public function setType($type) |
126
|
|
|
{ |
127
|
|
|
$this->assertNonEmptyString($type, 'type'); |
128
|
|
|
|
129
|
|
|
$this->type = $type; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return null|string |
134
|
|
|
*/ |
135
|
|
|
public function getSecondFactorId() |
136
|
|
|
{ |
137
|
|
|
return $this->secondFactorId; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param null|string $secondFactorId |
142
|
|
|
*/ |
143
|
|
|
public function setSecondFactorId($secondFactorId) |
144
|
|
|
{ |
145
|
|
|
$this->assertNonEmptyString($secondFactorId, 'secondFactorId'); |
146
|
|
|
|
147
|
|
|
$this->secondFactorId = $secondFactorId; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return null|string |
152
|
|
|
*/ |
153
|
|
|
public function getEmail() |
154
|
|
|
{ |
155
|
|
|
return $this->email; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param null|string $email |
160
|
|
|
*/ |
161
|
|
|
public function setEmail($email) |
162
|
|
|
{ |
163
|
|
|
$this->assertNonEmptyString($email, 'email'); |
164
|
|
|
|
165
|
|
|
$this->email = $email; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return null|string |
170
|
|
|
*/ |
171
|
|
|
public function getStatus() |
172
|
|
|
{ |
173
|
|
|
return $this->status; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $status |
178
|
|
|
*/ |
179
|
|
View Code Duplication |
public function setStatus($status) |
|
|
|
|
180
|
|
|
{ |
181
|
|
|
Assert\that($status)->choice( |
182
|
|
|
[self::STATUS_UNVERIFIED, self::STATUS_VERIFIED, self::STATUS_VETTED, self::STATUS_REVOKED, ''], |
183
|
|
|
'Invalid second factor status, must be one of the STATUS constants' |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
$this->status = $status ?: null; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return null|string |
191
|
|
|
*/ |
192
|
|
|
public function getInstitution() |
193
|
|
|
{ |
194
|
|
|
return $this->institution; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param null|string $institution |
199
|
|
|
*/ |
200
|
|
|
public function setInstitution($institution) |
201
|
|
|
{ |
202
|
|
|
$this->institution = $institution; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param string $orderBy |
207
|
|
|
*/ |
208
|
|
|
public function setOrderBy($orderBy) |
209
|
|
|
{ |
210
|
|
|
$this->assertNonEmptyString($orderBy, 'orderBy'); |
211
|
|
|
|
212
|
|
|
$this->orderBy = $orderBy; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param string|null $orderDirection |
217
|
|
|
*/ |
218
|
|
View Code Duplication |
public function setOrderDirection($orderDirection) |
|
|
|
|
219
|
|
|
{ |
220
|
|
|
Assert\that($orderDirection)->choice( |
221
|
|
|
['asc', 'desc', '', null], |
222
|
|
|
"Invalid order direction, must be one of 'asc', 'desc'" |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$this->orderDirection = $orderDirection ?: null; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
View Code Duplication |
private function assertNonEmptyString($value, $name) |
|
|
|
|
229
|
|
|
{ |
230
|
|
|
$message = sprintf( |
231
|
|
|
'"%s" must be a non-empty string, "%s" given', |
232
|
|
|
$name, |
233
|
|
|
(is_object($value) ? get_class($value) : gettype($value)) |
234
|
|
|
); |
235
|
|
|
|
236
|
|
|
Assert\that($value)->string($message)->notEmpty($message); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Return the Http Query string as should be used, MUST include the '?' prefix. |
241
|
|
|
* |
242
|
|
|
* @return string |
243
|
|
|
*/ |
244
|
|
View Code Duplication |
public function toHttpQuery() |
|
|
|
|
245
|
|
|
{ |
246
|
|
|
return '?' . http_build_query( |
247
|
|
|
array_filter( |
248
|
|
|
[ |
249
|
|
|
'actorInstitution' => $this->actorInstitution, |
250
|
|
|
'name' => $this->name, |
251
|
|
|
'type' => $this->type, |
252
|
|
|
'secondFactorId' => $this->secondFactorId, |
253
|
|
|
'email' => $this->email, |
254
|
|
|
'status' => $this->status, |
255
|
|
|
'institution' => $this->institution, |
256
|
|
|
'orderBy' => $this->orderBy, |
257
|
|
|
'orderDirection' => $this->orderDirection, |
258
|
|
|
'p' => $this->pageNumber, |
259
|
|
|
], |
260
|
|
|
function ($value) { |
261
|
|
|
return !is_null($value); |
262
|
|
|
} |
263
|
|
|
) |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.