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 $actorInstitution; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $institution; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private $identityId; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int |
43
|
|
|
*/ |
44
|
|
|
private $pageNumber; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string|null |
48
|
|
|
*/ |
49
|
|
|
private $orderBy = 'commonName'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string|null |
53
|
|
|
*/ |
54
|
|
|
private $orderDirection = 'asc'; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $institution |
|
|
|
|
58
|
|
|
* @param int $pageNumber |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function __construct($actorInstitution, $pageNumber) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$this->assertNonEmptyString($actorInstitution, 'actorInstitution'); |
63
|
|
|
Assert\that($pageNumber) |
64
|
|
|
->integer('Page number must be an integer') |
65
|
|
|
->min(0, 'Page number must be greater than or equal to 1'); |
66
|
|
|
|
67
|
|
|
$this->actorInstitution = $actorInstitution; |
68
|
|
|
$this->pageNumber = $pageNumber; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $institution |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
|
|
public function setInstitution($institution) |
76
|
|
|
{ |
77
|
|
|
$this->assertNonEmptyString($institution, 'institution'); |
78
|
|
|
|
79
|
|
|
$this->institution = $institution; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $identityId |
86
|
|
|
* @return RaListingSearchQuery |
87
|
|
|
*/ |
88
|
|
|
public function setIdentityId($identityId) |
89
|
|
|
{ |
90
|
|
|
$this->assertNonEmptyString($identityId, 'identityId'); |
91
|
|
|
|
92
|
|
|
$this->identityId = $identityId; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $orderBy |
99
|
|
|
* @return RaListingSearchQuery |
100
|
|
|
*/ |
101
|
|
|
public function setOrderBy($orderBy) |
102
|
|
|
{ |
103
|
|
|
$this->assertNonEmptyString($orderBy, 'orderBy'); |
104
|
|
|
|
105
|
|
|
$this->orderBy = $orderBy; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string|null $orderDirection |
112
|
|
|
* @return RaListingSearchQuery |
113
|
|
|
*/ |
114
|
|
View Code Duplication |
public function setOrderDirection($orderDirection) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
Assert\that($orderDirection)->choice( |
117
|
|
|
['asc', 'desc', '', null], |
118
|
|
|
"Invalid order direction, must be one of 'asc', 'desc'" |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->orderDirection = $orderDirection ?: null; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
View Code Duplication |
private function assertNonEmptyString($value, $parameterName) |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
$message = sprintf( |
129
|
|
|
'"%s" must be a non-empty string, "%s" given', |
130
|
|
|
$parameterName, |
131
|
|
|
(is_object($value) ? get_class($value) : gettype($value)) |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
Assert\that($value)->string($message)->notEmpty($message); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function toHttpQuery() |
138
|
|
|
{ |
139
|
|
|
return '?' . http_build_query( |
140
|
|
|
array_filter( |
141
|
|
|
[ |
142
|
|
|
'actorInstitution' => $this->actorInstitution, |
143
|
|
|
'institution' => $this->institution, |
144
|
|
|
'identityId ' => $this->identityId, |
145
|
|
|
'orderBy' => $this->orderBy, |
146
|
|
|
'orderDirection' => $this->orderDirection, |
147
|
|
|
'p' => $this->pageNumber, |
148
|
|
|
], |
149
|
|
|
function ($value) { |
150
|
|
|
return !is_null($value); |
151
|
|
|
} |
152
|
|
|
) |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.