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 RaListingSearchQuery implements HttpQuery |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $actorId; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $actorInstitution; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $name; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $email; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $role; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $raInstitution; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string|null |
58
|
|
|
*/ |
59
|
|
|
private $institution; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string|null |
63
|
|
|
*/ |
64
|
|
|
private $identityId; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var int |
68
|
|
|
*/ |
69
|
|
|
private $pageNumber; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var string|null |
73
|
|
|
*/ |
74
|
|
|
private $orderBy = 'commonName'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string|null |
78
|
|
|
*/ |
79
|
|
|
private $orderDirection = 'asc'; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $actorId |
83
|
|
|
* @param string string $actorInstitution |
84
|
|
|
* @param int $pageNumber |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function __construct($actorId, $actorInstitution, $pageNumber) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$this->assertNonEmptyString($actorId, 'actorId'); |
89
|
|
|
$this->assertNonEmptyString($actorInstitution, 'actorInstitution'); |
90
|
|
|
Assert\that($pageNumber) |
91
|
|
|
->integer('Page number must be an integer') |
92
|
|
|
->min(0, 'Page number must be greater than or equal to 1'); |
93
|
|
|
|
94
|
|
|
$this->actorId = $actorId; |
95
|
|
|
$this->actorInstitution = $actorInstitution; |
96
|
|
|
$this->pageNumber = $pageNumber; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $institution |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
|
|
public function setInstitution($institution) |
104
|
|
|
{ |
105
|
|
|
$this->assertNonEmptyString($institution, 'institution'); |
106
|
|
|
|
107
|
|
|
$this->institution = $institution; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $identityId |
114
|
|
|
* @return RaListingSearchQuery |
115
|
|
|
*/ |
116
|
|
|
public function setIdentityId($identityId) |
117
|
|
|
{ |
118
|
|
|
$this->assertNonEmptyString($identityId, 'identityId'); |
119
|
|
|
|
120
|
|
|
$this->identityId = $identityId; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $orderBy |
127
|
|
|
* @return RaListingSearchQuery |
128
|
|
|
*/ |
129
|
|
|
public function setOrderBy($orderBy) |
130
|
|
|
{ |
131
|
|
|
$this->assertNonEmptyString($orderBy, 'orderBy'); |
132
|
|
|
|
133
|
|
|
$this->orderBy = $orderBy; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string|null $orderDirection |
140
|
|
|
* @return RaListingSearchQuery |
141
|
|
|
*/ |
142
|
|
View Code Duplication |
public function setOrderDirection($orderDirection) |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
Assert\that($orderDirection)->choice( |
145
|
|
|
['asc', 'desc', '', null], |
146
|
|
|
"Invalid order direction, must be one of 'asc', 'desc'" |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$this->orderDirection = $orderDirection ?: null; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string $name |
156
|
|
|
* @return RaListingSearchQuery |
157
|
|
|
*/ |
158
|
|
|
public function setName($name) |
159
|
|
|
{ |
160
|
|
|
$this->assertNonEmptyString($name, 'name'); |
161
|
|
|
$this->name = $name; |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $email |
167
|
|
|
* @return RaListingSearchQuery |
168
|
|
|
*/ |
169
|
|
|
public function setEmail($email) |
170
|
|
|
{ |
171
|
|
|
$this->assertNonEmptyString($email, 'email'); |
172
|
|
|
$this->email = $email; |
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $role |
178
|
|
|
* @return RaListingSearchQuery |
179
|
|
|
*/ |
180
|
|
|
public function setRole($role) |
181
|
|
|
{ |
182
|
|
|
$this->assertNonEmptyString($role, 'role'); |
183
|
|
|
$this->role = $role; |
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param string $raInstitution |
189
|
|
|
* @return RaListingSearchQuery |
190
|
|
|
*/ |
191
|
|
|
public function setRaInstitution($raInstitution) |
192
|
|
|
{ |
193
|
|
|
$this->assertNonEmptyString($raInstitution, 'raInstitution'); |
194
|
|
|
$this->raInstitution = $raInstitution; |
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
View Code Duplication |
private function assertNonEmptyString($value, $parameterName) |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
$message = sprintf( |
201
|
|
|
'"%s" must be a non-empty string, "%s" given', |
202
|
|
|
$parameterName, |
203
|
|
|
(is_object($value) ? get_class($value) : gettype($value)) |
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
Assert\that($value)->string($message)->notEmpty($message); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
View Code Duplication |
public function toHttpQuery() |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
return '?'.http_build_query( |
212
|
|
|
array_filter( |
213
|
|
|
[ |
214
|
|
|
'actorId' => $this->actorId, |
215
|
|
|
'actorInstitution' => $this->actorInstitution, |
216
|
|
|
'institution' => $this->institution, |
217
|
|
|
'identityId' => $this->identityId, |
218
|
|
|
'name' => $this->name, |
219
|
|
|
'email' => $this->email, |
220
|
|
|
'role' => $this->role, |
221
|
|
|
'raInstitution' => $this->raInstitution, |
222
|
|
|
'orderBy' => $this->orderBy, |
223
|
|
|
'orderDirection' => $this->orderDirection, |
224
|
|
|
'p' => $this->pageNumber, |
225
|
|
|
], |
226
|
|
|
function ($value) { |
227
|
|
|
return !is_null($value); |
228
|
|
|
} |
229
|
|
|
) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
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.