1 | <?php |
||||||||||
2 | /** |
||||||||||
3 | * @author: RunnerLee |
||||||||||
4 | * @email: [email protected] |
||||||||||
5 | * @time: 2018-12 |
||||||||||
6 | */ |
||||||||||
7 | |||||||||||
8 | namespace Runner\Validator\Concerns; |
||||||||||
9 | |||||||||||
10 | use Runner\Validator\Validator; |
||||||||||
11 | |||||||||||
12 | trait ValidatesAttributes |
||||||||||
13 | { |
||||||||||
14 | /** |
||||||||||
15 | * @param $field |
||||||||||
16 | * @param $value |
||||||||||
17 | * @param array $parameters |
||||||||||
18 | * @param Validator $validator |
||||||||||
19 | * |
||||||||||
20 | * @return bool |
||||||||||
21 | */ |
||||||||||
22 | 1 | public function validateAccept($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
23 | { |
||||||||||
24 | 1 | return in_array(strtolower($value), ['yes', 'on', '1', 1, true], true); |
|||||||||
25 | } |
||||||||||
26 | |||||||||||
27 | /** |
||||||||||
28 | * @param $field |
||||||||||
29 | * @param $value |
||||||||||
30 | * @param array $parameters |
||||||||||
31 | * @param Validator $validator |
||||||||||
32 | * |
||||||||||
33 | * @return bool |
||||||||||
34 | */ |
||||||||||
35 | 1 | public function validateNumeric($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
36 | { |
||||||||||
37 | 1 | return false !== filter_var($value, FILTER_VALIDATE_INT) || false !== filter_var($value, FILTER_VALIDATE_FLOAT); |
|||||||||
38 | } |
||||||||||
39 | |||||||||||
40 | /** |
||||||||||
41 | * @param $field |
||||||||||
42 | * @param $value |
||||||||||
43 | * @param array $parameters |
||||||||||
44 | * @param Validator $validator |
||||||||||
45 | * |
||||||||||
46 | * @return bool |
||||||||||
47 | */ |
||||||||||
48 | 2 | public function validateInteger($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
49 | { |
||||||||||
50 | 2 | return false !== filter_var($value, FILTER_VALIDATE_INT); |
|||||||||
51 | } |
||||||||||
52 | |||||||||||
53 | /** |
||||||||||
54 | * @param $field |
||||||||||
55 | * @param $value |
||||||||||
56 | * @param array $parameters |
||||||||||
57 | * @param Validator $validator |
||||||||||
58 | * |
||||||||||
59 | * @return bool |
||||||||||
60 | */ |
||||||||||
61 | 1 | public function validateFloat($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
62 | { |
||||||||||
63 | 1 | return false !== filter_var($value, FILTER_VALIDATE_FLOAT); |
|||||||||
64 | } |
||||||||||
65 | |||||||||||
66 | /** |
||||||||||
67 | * @param $field |
||||||||||
68 | * @param $value |
||||||||||
69 | * @param array $parameters |
||||||||||
70 | * @param Validator $validator |
||||||||||
71 | * |
||||||||||
72 | * @return bool |
||||||||||
73 | */ |
||||||||||
74 | 2 | public function validateSize($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
75 | { |
||||||||||
76 | 2 | $size = filter_var($parameters[0], FILTER_VALIDATE_INT); |
|||||||||
77 | 2 | false === $size && $size = filter_var($parameters[0], FILTER_VALIDATE_FLOAT); |
|||||||||
78 | |||||||||||
79 | 2 | return $this->getSize($field, $value) === $size; |
|||||||||
80 | } |
||||||||||
81 | |||||||||||
82 | /** |
||||||||||
83 | * @param $field |
||||||||||
84 | * @param $value |
||||||||||
85 | * @param array $parameters |
||||||||||
86 | * @param Validator $validator |
||||||||||
87 | * |
||||||||||
88 | * @return bool |
||||||||||
89 | */ |
||||||||||
90 | 1 | public function validateUrl($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
91 | { |
||||||||||
92 | 1 | return false !== filter_var($value, FILTER_VALIDATE_URL); |
|||||||||
93 | } |
||||||||||
94 | |||||||||||
95 | /** |
||||||||||
96 | * @param $field |
||||||||||
97 | * @param $value |
||||||||||
98 | * @param array $parameters |
||||||||||
99 | * @param Validator $validator |
||||||||||
100 | * |
||||||||||
101 | * @return bool |
||||||||||
102 | */ |
||||||||||
103 | 1 | public function validateBoolean($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
104 | { |
||||||||||
105 | 1 | return in_array($value, [true, false, 0, 1, '0', '1'], true); |
|||||||||
106 | } |
||||||||||
107 | |||||||||||
108 | /** |
||||||||||
109 | * @param $field |
||||||||||
110 | * @param $value |
||||||||||
111 | * @param array $parameters |
||||||||||
112 | * @param Validator $validator |
||||||||||
113 | * |
||||||||||
114 | * @return bool |
||||||||||
115 | */ |
||||||||||
116 | 1 | public function validateConfirm($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
117 | { |
||||||||||
118 | 1 | return $value === $this->data[$parameters[0]]; |
|||||||||
119 | } |
||||||||||
120 | |||||||||||
121 | /** |
||||||||||
122 | * @param $field |
||||||||||
123 | * @param $value |
||||||||||
124 | * @param array $parameters |
||||||||||
125 | * @param Validator $validator |
||||||||||
126 | * |
||||||||||
127 | * @return bool |
||||||||||
128 | */ |
||||||||||
129 | 1 | public function validateDate($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
130 | { |
||||||||||
131 | 1 | return false !== strtotime($value); |
|||||||||
132 | } |
||||||||||
133 | |||||||||||
134 | /** |
||||||||||
135 | * 邮箱地址 |
||||||||||
136 | * |
||||||||||
137 | * @param $field |
||||||||||
138 | * @param $value |
||||||||||
139 | * @param array $parameters |
||||||||||
140 | * @param Validator $validator |
||||||||||
141 | * |
||||||||||
142 | * @return bool |
||||||||||
143 | */ |
||||||||||
144 | 1 | public function validateEmail($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
145 | { |
||||||||||
146 | 1 | return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|||||||||
147 | } |
||||||||||
148 | |||||||||||
149 | /** |
||||||||||
150 | * @param $field |
||||||||||
151 | * @param $value |
||||||||||
152 | * @param array $parameters |
||||||||||
153 | * @param Validator $validator |
||||||||||
154 | * |
||||||||||
155 | * @return bool |
||||||||||
156 | */ |
||||||||||
157 | 1 | public function validateRequired($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
158 | { |
||||||||||
159 | 1 | return !is_null($value); |
|||||||||
160 | } |
||||||||||
161 | |||||||||||
162 | /** |
||||||||||
163 | * @param $field |
||||||||||
164 | * @param $value |
||||||||||
165 | * @param array $parameters |
||||||||||
166 | * @param Validator $validator |
||||||||||
167 | * |
||||||||||
168 | * @return bool |
||||||||||
169 | */ |
||||||||||
170 | 1 | public function validateRequiredWith($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
171 | { |
||||||||||
172 | 1 | return !is_null($value) || !array_key_exists($parameters[0], $this->data); |
|||||||||
173 | } |
||||||||||
174 | |||||||||||
175 | /** |
||||||||||
176 | * @param $field |
||||||||||
177 | * @param $value |
||||||||||
178 | * @param array $parameters |
||||||||||
179 | * @param Validator $validator |
||||||||||
180 | * |
||||||||||
181 | * @return bool |
||||||||||
182 | */ |
||||||||||
183 | 1 | public function validateRequiredWithout($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
184 | { |
||||||||||
185 | 1 | return !is_null($value) || array_key_exists($parameters[0], $this->data); |
|||||||||
186 | } |
||||||||||
187 | |||||||||||
188 | /** |
||||||||||
189 | * @param $field |
||||||||||
190 | * @param $value |
||||||||||
191 | * @param array $parameters |
||||||||||
192 | * @param Validator $validator |
||||||||||
193 | * |
||||||||||
194 | * @return bool |
||||||||||
195 | */ |
||||||||||
196 | 1 | public function validateRequiredIf($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
197 | { |
||||||||||
198 | 1 | $otherField = array_shift($parameters); |
|||||||||
199 | |||||||||||
200 | 1 | return !is_null($value) || ( |
|||||||||
201 | 1 | !array_key_exists($otherField, $this->data) || false === array_search($this->data[$otherField], $parameters) |
|||||||||
202 | ); |
||||||||||
203 | } |
||||||||||
204 | |||||||||||
205 | /** |
||||||||||
206 | * @param $field |
||||||||||
207 | * @param $value |
||||||||||
208 | * @param array $parameters |
||||||||||
209 | * @param Validator $validator |
||||||||||
210 | * |
||||||||||
211 | * @return bool |
||||||||||
212 | */ |
||||||||||
213 | 1 | public function validateRequiredUnless($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
214 | { |
||||||||||
215 | 1 | $otherField = array_shift($parameters); |
|||||||||
216 | |||||||||||
217 | 1 | return !is_null($value) || ( |
|||||||||
218 | 1 | !array_key_exists($otherField, $this->data) || false !== array_search($this->data[$otherField], $parameters) |
|||||||||
219 | ); |
||||||||||
220 | } |
||||||||||
221 | |||||||||||
222 | /** |
||||||||||
223 | * @param $field |
||||||||||
224 | * @param $value |
||||||||||
225 | * @param array $parameters |
||||||||||
226 | * |
||||||||||
227 | * @return bool |
||||||||||
228 | */ |
||||||||||
229 | 1 | public function validateArray($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
230 | { |
||||||||||
231 | 1 | return is_array($value); |
|||||||||
232 | } |
||||||||||
233 | |||||||||||
234 | /** |
||||||||||
235 | * @param $field |
||||||||||
236 | * @param $value |
||||||||||
237 | * @param array $parameters |
||||||||||
238 | * @param Validator $validator |
||||||||||
239 | * |
||||||||||
240 | * @return bool |
||||||||||
241 | */ |
||||||||||
242 | 1 | public function validateString($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
243 | { |
||||||||||
244 | 1 | return is_string($value); |
|||||||||
245 | } |
||||||||||
246 | |||||||||||
247 | /** |
||||||||||
248 | * @param $field |
||||||||||
249 | * @param $value |
||||||||||
250 | * @param array $parameters |
||||||||||
251 | * @param Validator $validator |
||||||||||
252 | * |
||||||||||
253 | * @return bool |
||||||||||
254 | */ |
||||||||||
255 | 1 | public function validateNullable($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$value is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
256 | { |
||||||||||
257 | 1 | return true; |
|||||||||
258 | } |
||||||||||
259 | |||||||||||
260 | /** |
||||||||||
261 | * @param $field |
||||||||||
262 | * @param $value |
||||||||||
263 | * @param array $parameters |
||||||||||
264 | * @param Validator $validator |
||||||||||
265 | * |
||||||||||
266 | * @return bool |
||||||||||
267 | */ |
||||||||||
268 | 1 | public function validateMin($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
269 | { |
||||||||||
270 | 1 | return $this->getSize($field, $value) >= $parameters[0]; |
|||||||||
271 | } |
||||||||||
272 | |||||||||||
273 | /** |
||||||||||
274 | * @param $field |
||||||||||
275 | * @param $value |
||||||||||
276 | * @param array $parameters |
||||||||||
277 | * @param Validator $validator |
||||||||||
278 | * |
||||||||||
279 | * @return bool |
||||||||||
280 | */ |
||||||||||
281 | 1 | public function validateMax($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
282 | { |
||||||||||
283 | 1 | return $this->getSize($field, $value) <= $parameters[0]; |
|||||||||
284 | } |
||||||||||
285 | |||||||||||
286 | /** |
||||||||||
287 | * @param $field |
||||||||||
288 | * @param $value |
||||||||||
289 | * @param array $parameters |
||||||||||
290 | * @param Validator $validator |
||||||||||
291 | * |
||||||||||
292 | * @return bool |
||||||||||
293 | */ |
||||||||||
294 | 1 | public function validateRange($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
295 | { |
||||||||||
296 | 1 | $size = $this->getSize($field, $value); |
|||||||||
297 | 1 | if (!isset($parameters[0])) { |
|||||||||
298 | 1 | return false; |
|||||||||
299 | } |
||||||||||
300 | 1 | if (isset($parameters[1])) { |
|||||||||
301 | 1 | if ('' === $parameters[0]) { |
|||||||||
302 | 1 | if ('' === $parameters[1]) { |
|||||||||
303 | 1 | return false; |
|||||||||
304 | } |
||||||||||
305 | |||||||||||
306 | 1 | return $size <= $parameters[1]; |
|||||||||
307 | } |
||||||||||
308 | 1 | if ('' === $parameters[1]) { |
|||||||||
309 | 1 | return $size >= $parameters[0]; |
|||||||||
310 | } |
||||||||||
311 | |||||||||||
312 | 1 | return $size >= $parameters[0] && $size <= $parameters[1]; |
|||||||||
313 | } |
||||||||||
314 | |||||||||||
315 | 1 | return '' === $parameters[0] ? false : ($size >= $parameters[0]); |
|||||||||
316 | } |
||||||||||
317 | |||||||||||
318 | /** |
||||||||||
319 | * @param $field |
||||||||||
320 | * @param $value |
||||||||||
321 | * @param array $parameters |
||||||||||
322 | * @param Validator $validator |
||||||||||
323 | * |
||||||||||
324 | * @return bool |
||||||||||
325 | */ |
||||||||||
326 | 1 | public function validateRegex($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
327 | { |
||||||||||
328 | 1 | return (bool) preg_match($parameters[0], $value); |
|||||||||
329 | } |
||||||||||
330 | |||||||||||
331 | /** |
||||||||||
332 | * @param $field |
||||||||||
333 | * @param $value |
||||||||||
334 | * @param array $parameters |
||||||||||
335 | * @param Validator $validator |
||||||||||
336 | * |
||||||||||
337 | * @return bool |
||||||||||
338 | */ |
||||||||||
339 | 1 | public function validateIn($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
340 | { |
||||||||||
341 | 1 | return in_array($value, $parameters, true); |
|||||||||
342 | } |
||||||||||
343 | |||||||||||
344 | /** |
||||||||||
345 | * @param $field |
||||||||||
346 | * @param $value |
||||||||||
347 | * @param array $parameters |
||||||||||
348 | * @param Validator $validator |
||||||||||
349 | * |
||||||||||
350 | * @return bool |
||||||||||
351 | */ |
||||||||||
352 | 1 | public function validateIp($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
353 | { |
||||||||||
354 | 1 | return false !== filter_var($value, FILTER_VALIDATE_IP); |
|||||||||
355 | } |
||||||||||
356 | |||||||||||
357 | /** |
||||||||||
358 | * @param $field |
||||||||||
359 | * @param $value |
||||||||||
360 | * @param array $parameters |
||||||||||
361 | * @param Validator $validator |
||||||||||
362 | * |
||||||||||
363 | * @return bool |
||||||||||
364 | */ |
||||||||||
365 | 1 | public function validateDateFormat($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
366 | { |
||||||||||
367 | 1 | return !(bool) date_parse_from_format($parameters[0], $value)['error_count']; |
|||||||||
368 | } |
||||||||||
369 | |||||||||||
370 | /** |
||||||||||
371 | * @param $field |
||||||||||
372 | * @param $value |
||||||||||
373 | * @param array $parameters |
||||||||||
374 | * @param Validator $validator |
||||||||||
375 | * |
||||||||||
376 | * @return bool |
||||||||||
377 | */ |
||||||||||
378 | 1 | public function validateDateBefore($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
379 | { |
||||||||||
380 | 1 | return strtotime($value) < strtotime($parameters[0]); |
|||||||||
381 | } |
||||||||||
382 | |||||||||||
383 | /** |
||||||||||
384 | * @param $field |
||||||||||
385 | * @param $value |
||||||||||
386 | * @param array $parameters |
||||||||||
387 | * @param Validator $validator |
||||||||||
388 | * |
||||||||||
389 | * @return bool |
||||||||||
390 | */ |
||||||||||
391 | 1 | public function validateDateAfter($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
392 | { |
||||||||||
393 | 1 | return strtotime($value) > strtotime($parameters[0]); |
|||||||||
394 | } |
||||||||||
395 | |||||||||||
396 | /** |
||||||||||
397 | * @param $field |
||||||||||
398 | * @param $value |
||||||||||
399 | * @param array $parameters |
||||||||||
400 | * @param Validator $validator |
||||||||||
401 | * |
||||||||||
402 | * @return bool |
||||||||||
403 | */ |
||||||||||
404 | 1 | public function validateJson($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$parameters is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
405 | { |
||||||||||
406 | 1 | return is_array(json_decode($value, true)); |
|||||||||
407 | } |
||||||||||
408 | |||||||||||
409 | /** |
||||||||||
410 | * @param $field |
||||||||||
411 | * @param $value |
||||||||||
412 | * @param array $parameters |
||||||||||
413 | * @param Validator $validator |
||||||||||
414 | * |
||||||||||
415 | * @return bool |
||||||||||
416 | */ |
||||||||||
417 | 1 | public function validateDiff($field, $value, array $parameters, Validator $validator) |
|||||||||
0 ignored issues
–
show
The parameter
$field is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$validator is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||||
418 | { |
||||||||||
419 | 1 | $specifyField = array_shift($parameters); |
|||||||||
420 | |||||||||||
421 | 1 | return array_key_exists($specifyField, $this->data) && $value !== $this->data[$specifyField]; |
|||||||||
422 | } |
||||||||||
423 | |||||||||||
424 | /** |
||||||||||
425 | * @param $field |
||||||||||
426 | * @param $value |
||||||||||
427 | * |
||||||||||
428 | * @return int|float |
||||||||||
429 | */ |
||||||||||
430 | 2 | public function getSize($field, $value) |
|||||||||
431 | { |
||||||||||
432 | switch (true) { |
||||||||||
433 | 2 | case isset($this->ruleGroups[$field]['String']) && is_string($value): |
|||||||||
434 | 1 | return strlen($value); |
|||||||||
435 | 2 | case is_array($value): |
|||||||||
436 | 1 | return count($value); |
|||||||||
437 | 2 | case false !== $temp = filter_var($value, FILTER_VALIDATE_INT): |
|||||||||
438 | 1 | return $temp; |
|||||||||
439 | 2 | case false !== $temp = filter_var($value, FILTER_VALIDATE_FLOAT): |
|||||||||
440 | 1 | return $temp; |
|||||||||
441 | default: |
||||||||||
442 | 2 | return mb_strlen($value); |
|||||||||
443 | } |
||||||||||
444 | } |
||||||||||
445 | } |
||||||||||
446 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.