Conditions | 1 |
Paths | 1 |
Total Lines | 518 |
Code Lines | 371 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
68 | public function provideValidFilterData() : array |
||
69 | { |
||
70 | return [ |
||
71 | 'not required field not present' => [ |
||
72 | 'spec' => ['fieldOne' => ['required' => false]], |
||
73 | 'input' => [], |
||
74 | 'options' => [], |
||
75 | 'result' => [true, [], null, []], |
||
76 | ], |
||
77 | 'Required With A Default Without Input' => [ |
||
78 | 'spec' => ['fieldOne' => ['required' => true, 'default' => 'theDefault']], |
||
79 | 'input' => [], |
||
80 | 'options' => [], |
||
81 | 'result' => [true, ['fieldOne' => 'theDefault'], null, []], |
||
82 | ], |
||
83 | 'Required With A Null Default Without Input' => [ |
||
84 | 'spec' => ['fieldOne' => ['required' => true, 'default' => null]], |
||
85 | 'input' => [], |
||
86 | 'options' => [], |
||
87 | 'result' => [true, ['fieldOne' => null], null, []], |
||
88 | ], |
||
89 | 'Required With A Default With Input' => [ |
||
90 | 'spec' => ['fieldOne' => ['required' => true, 'default' => 'theDefault']], |
||
91 | 'input' => ['fieldOne' => 'notTheDefault'], |
||
92 | 'options' => [], |
||
93 | 'result' => [true, ['fieldOne' => 'notTheDefault'], null, []], |
||
94 | ], |
||
95 | 'Not Required With A Default Without Input' => [ |
||
96 | 'spec' => ['fieldOne' => ['default' => 'theDefault']], |
||
97 | 'input' => [], |
||
98 | 'options' => [], |
||
99 | 'result' => [true, ['fieldOne' => 'theDefault'], null, []], |
||
100 | ], |
||
101 | 'Not Required With A Default With Input' => [ |
||
102 | 'spec' => ['fieldOne' => ['default' => 'theDefault']], |
||
103 | 'input' => ['fieldOne' => 'notTheDefault'], |
||
104 | 'options' => [], |
||
105 | 'result' => [true, ['fieldOne' => 'notTheDefault'], null, []], |
||
106 | ], |
||
107 | 'Required Fail' => [ |
||
108 | 'spec' => ['fieldOne' => ['required' => true]], |
||
109 | 'input' => [], |
||
110 | 'options' => [], |
||
111 | 'result' => [false, null, "Field 'fieldOne' was required and not present", []], |
||
112 | ], |
||
113 | 'Required Default Pass' => [ |
||
114 | 'spec' => ['fieldOne' => []], |
||
115 | 'input' => [], |
||
116 | 'options' => [], |
||
117 | 'result' => [true, [], null, []], |
||
118 | ], |
||
119 | 'requiredDefaultFail' => [ |
||
120 | 'spec' => ['fieldOne' => []], |
||
121 | 'input' => [], |
||
122 | 'options' => ['defaultRequired' => true], |
||
123 | 'result' => [false, null, "Field 'fieldOne' was required and not present", []], |
||
124 | ], |
||
125 | 'filterPass' => [ |
||
126 | 'spec' => ['fieldOne' => [['floatval']]], |
||
127 | 'input' => ['fieldOne' => '3.14'], |
||
128 | 'options' => [], |
||
129 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
130 | ], |
||
131 | 'filterDefaultShortNamePass' => [ |
||
132 | 'spec' => ['fieldOne' => [['float']]], |
||
133 | 'input' => ['fieldOne' => '3.14'], |
||
134 | 'options' => [], |
||
135 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
136 | ], |
||
137 | 'filterFail' => [ |
||
138 | 'spec' => ['fieldOne' => [['\TraderInteractive\FiltererTest::failingFilter']]], |
||
139 | 'input' => ['fieldOne' => 'valueOne'], |
||
140 | 'options' => [], |
||
141 | 'result' => [ |
||
142 | false, |
||
143 | null, |
||
144 | "Field 'fieldOne' with value 'valueOne' failed filtering, message 'i failed'", |
||
145 | [], |
||
146 | ], |
||
147 | ], |
||
148 | 'chainPass' => [ |
||
149 | 'spec' => ['fieldOne' => [['trim', 'a'], ['floatval']]], |
||
150 | 'input' => ['fieldOne' => 'a3.14'], |
||
151 | 'options' => [], |
||
152 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
153 | ], |
||
154 | 'chainFail' => [ |
||
155 | 'spec' => ['fieldOne' => [['trim'], ['\TraderInteractive\FiltererTest::failingFilter']]], |
||
156 | 'input' => ['fieldOne' => 'the value'], |
||
157 | 'options' => [], |
||
158 | 'result' => [ |
||
159 | false, |
||
160 | null, |
||
161 | "Field 'fieldOne' with value 'the value' failed filtering, message 'i failed'", |
||
162 | [], |
||
163 | ], |
||
164 | ], |
||
165 | 'multiInputPass' => [ |
||
166 | 'spec' => ['fieldOne' => [['trim']], 'fieldTwo' => [['strtoupper']]], |
||
167 | 'input' => ['fieldOne' => ' value', 'fieldTwo' => 'bob'], |
||
168 | 'options' => [], |
||
169 | 'result' => [true, ['fieldOne' => 'value', 'fieldTwo' => 'BOB'], null, []], |
||
170 | ], |
||
171 | 'multiInputFail' => [ |
||
172 | 'spec' => [ |
||
173 | 'fieldOne' => [['\TraderInteractive\FiltererTest::failingFilter']], |
||
174 | 'fieldTwo' => [['\TraderInteractive\FiltererTest::failingFilter']], |
||
175 | ], |
||
176 | 'input' => ['fieldOne' => 'value one', 'fieldTwo' => 'value two'], |
||
177 | 'options' => [], |
||
178 | 'result' => [ |
||
179 | false, |
||
180 | null, |
||
181 | "Field 'fieldOne' with value 'value one' failed filtering, message 'i failed'\n" |
||
182 | . "Field 'fieldTwo' with value 'value two' failed filtering, message 'i failed'", |
||
183 | [], |
||
184 | ], |
||
185 | ], |
||
186 | 'emptyFilter' => [ |
||
187 | 'spec' => ['fieldOne' => [[]]], |
||
188 | 'input' => ['fieldOne' => 0], |
||
189 | 'options' => [], |
||
190 | 'result' => [true, ['fieldOne' => 0], null, []], |
||
191 | ], |
||
192 | 'unknownsAllowed' => [ |
||
193 | 'spec' => [], |
||
194 | 'input'=> ['fieldTwo' => 0], |
||
195 | 'options' => ['allowUnknowns' => true], |
||
196 | 'result' => [true, [], null, ['fieldTwo' => 0]], |
||
197 | ], |
||
198 | 'unknownsNotAllowed' => [ |
||
199 | 'spec' => [], |
||
200 | 'input' => ['fieldTwo' => 0], |
||
201 | 'options' => [], |
||
202 | 'result' => [false, null, "Field 'fieldTwo' with value '0' is unknown", ['fieldTwo' => 0]], |
||
203 | ], |
||
204 | 'objectFilter' => [ |
||
205 | 'spec' => ['fieldOne' => [[[$this, 'passingFilter']]]], |
||
206 | 'input' => ['fieldOne' => 'foo'], |
||
207 | 'options' => [], |
||
208 | 'result' => [true, ['fieldOne' => 'fooboo'], null, []], |
||
209 | ], |
||
210 | 'filterWithCustomError' => [ |
||
211 | 'spec' => [ |
||
212 | 'fieldOne' => [ |
||
213 | 'error' => 'My custom error message', |
||
214 | ['\TraderInteractive\FiltererTest::failingFilter'], |
||
215 | ], |
||
216 | ], |
||
217 | 'input' => ['fieldOne' => 'valueOne'], |
||
218 | 'options' => [], |
||
219 | 'result' => [false, null, 'My custom error message', []], |
||
220 | ], |
||
221 | 'filterWithCustomErrorContainingValuePlaceholder' => [ |
||
222 | 'spec' => [ |
||
223 | 'fieldOne' => [ |
||
224 | 'error' => "The value '{value}' is invalid.", |
||
225 | ['uint'], |
||
226 | ], |
||
227 | ], |
||
228 | 'input' => ['fieldOne' => 'abc'], |
||
229 | 'options' => [], |
||
230 | 'result' => [false, null, "The value 'abc' is invalid.", []], |
||
231 | ], |
||
232 | 'arrayizeAliasIsCalledProperly' => [ |
||
233 | 'spec' => ['field' => [['arrayize']]], |
||
234 | 'input' => ['field' => 'a string value'], |
||
235 | 'options' => [], |
||
236 | 'result' => [true, ['field' => ['a string value']], null, []], |
||
237 | ], |
||
238 | 'concatAliasIsCalledProperly' => [ |
||
239 | 'spec' => ['field' => [['concat', '%', '%']]], |
||
240 | 'input' => ['field' => 'value'], |
||
241 | 'options' => [], |
||
242 | 'result' => [true, ['field' => '%value%'], null, []], |
||
243 | ], |
||
244 | 'translate alias' => [ |
||
245 | 'spec' => ['field' => [['translate', ['active' => 'A', 'inactive' => 'I']]]], |
||
246 | 'input' => ['field' => 'inactive'], |
||
247 | 'options' => [], |
||
248 | 'result' => [true, ['field' => 'I'], null, []], |
||
249 | ], |
||
250 | 'redact alias' => [ |
||
251 | 'spec' => ['field' => [['redact', ['other'], '*']]], |
||
252 | 'input' => ['field' => 'one or other'], |
||
253 | 'options' => [], |
||
254 | 'result' => [true, ['field' => 'one or *****'], null, []], |
||
255 | ], |
||
256 | 'compress-string alias' => [ |
||
257 | 'spec' => ['field' => [['compress-string']]], |
||
258 | 'input' => ['field' => ' a string with extra spaces '], |
||
259 | 'options' => [], |
||
260 | 'result' => [true, ['field' => 'a string with extra spaces'], null, []], |
||
261 | ], |
||
262 | 'compress-string alias include newlines' => [ |
||
263 | 'spec' => ['field' => [['compress-string', true]]], |
||
264 | 'input' => ['field' => " a string\n with\nnewlines and extra spaces\n "], |
||
265 | 'options' => [], |
||
266 | 'result' => [true, ['field' => 'a string with newlines and extra spaces'], null, []], |
||
267 | ], |
||
268 | 'conflicts with single' => [ |
||
269 | 'spec' => [ |
||
270 | 'fieldOne' => [FilterOptions::CONFLICTS_WITH => 'fieldThree', ['string']], |
||
271 | 'fieldTwo' => [['string']], |
||
272 | 'fieldThree' => [FilterOptions::CONFLICTS_WITH => 'fieldOne', ['string']], |
||
273 | ], |
||
274 | 'input' => [ |
||
275 | 'fieldOne' => 'abc', |
||
276 | 'fieldTwo' => '123', |
||
277 | 'fieldThree' => 'xyz', |
||
278 | ], |
||
279 | 'options' => [], |
||
280 | 'result' => [ |
||
281 | false, |
||
282 | null, |
||
283 | "Field 'fieldOne' cannot be given if field 'fieldThree' is present.\n" |
||
284 | . "Field 'fieldThree' cannot be given if field 'fieldOne' is present.", |
||
285 | [], |
||
286 | ], |
||
287 | ], |
||
288 | 'conflicts with multiple' => [ |
||
289 | 'spec' => [ |
||
290 | 'fieldOne' => [FilterOptions::CONFLICTS_WITH => ['fieldTwo', 'fieldThree'], ['string']], |
||
291 | 'fieldTwo' => [['string']], |
||
292 | 'fieldThree' => [['string']], |
||
293 | ], |
||
294 | 'input' => [ |
||
295 | 'fieldOne' => 'abc', |
||
296 | 'fieldTwo' => '123', |
||
297 | ], |
||
298 | 'options' => [], |
||
299 | 'result' => [ |
||
300 | false, |
||
301 | null, |
||
302 | "Field 'fieldOne' cannot be given if field 'fieldTwo' is present.", |
||
303 | [], |
||
304 | ], |
||
305 | ], |
||
306 | 'conflicts with not present' => [ |
||
307 | 'spec' => [ |
||
308 | 'fieldOne' => [FilterOptions::CONFLICTS_WITH => 'fieldThree', ['string']], |
||
309 | 'fieldTwo' => [['string']], |
||
310 | ], |
||
311 | 'input' => [ |
||
312 | 'fieldOne' => 'abc', |
||
313 | 'fieldTwo' => '123', |
||
314 | ], |
||
315 | 'options' => [], |
||
316 | 'result' => [ |
||
317 | true, |
||
318 | [ |
||
319 | 'fieldOne' => 'abc', |
||
320 | 'fieldTwo' => '123', |
||
321 | ], |
||
322 | null, |
||
323 | [], |
||
324 | ], |
||
325 | ], |
||
326 | 'uses' => [ |
||
327 | 'spec' => [ |
||
328 | 'fieldOne' => [['uint']], |
||
329 | 'fieldTwo' => [ |
||
330 | ['uint'], |
||
331 | [ |
||
332 | FilterOptions::USES => ['fieldOne'], |
||
333 | function (int $input, int $fieldOneValue) : int { |
||
334 | return $input * $fieldOneValue; |
||
335 | }, |
||
336 | ], |
||
337 | ], |
||
338 | ], |
||
339 | 'input' => [ |
||
340 | 'fieldOne' => '5', |
||
341 | 'fieldTwo' => '2', |
||
342 | ], |
||
343 | 'options' => [], |
||
344 | 'result' => [ |
||
345 | true, |
||
346 | [ |
||
347 | 'fieldOne' => 5, |
||
348 | 'fieldTwo' => 10, |
||
349 | ], |
||
350 | null, |
||
351 | [], |
||
352 | ], |
||
353 | ], |
||
354 | 'input order does not matter for uses' => [ |
||
355 | 'spec' => [ |
||
356 | 'fieldOne' => [['uint']], |
||
357 | 'fieldTwo' => [ |
||
358 | ['uint'], |
||
359 | [ |
||
360 | FilterOptions::USES => ['fieldOne'], |
||
361 | function (int $input, int $fieldOneValue) : int { |
||
362 | return $input * $fieldOneValue; |
||
363 | }, |
||
364 | ], |
||
365 | ], |
||
366 | ], |
||
367 | 'input' => [ |
||
368 | 'fieldTwo' => '2', |
||
369 | 'fieldOne' => '5', |
||
370 | ], |
||
371 | 'options' => [], |
||
372 | 'result' => [ |
||
373 | true, |
||
374 | [ |
||
375 | 'fieldOne' => 5, |
||
376 | 'fieldTwo' => 10, |
||
377 | ], |
||
378 | null, |
||
379 | [], |
||
380 | ], |
||
381 | ], |
||
382 | 'uses missing field' => [ |
||
383 | 'spec' => [ |
||
384 | 'fieldOne' => [['uint']], |
||
385 | 'fieldTwo' => [ |
||
386 | ['uint'], |
||
387 | [ |
||
388 | FilterOptions::USES => ['fieldOne'], |
||
389 | function (int $input, int $fieldOneValue) : int { |
||
390 | return $input * $fieldOneValue; |
||
391 | }, |
||
392 | ], |
||
393 | ], |
||
394 | ], |
||
395 | 'input' => [ |
||
396 | 'fieldTwo' => '2', |
||
397 | ], |
||
398 | 'options' => [], |
||
399 | 'result' => [ |
||
400 | false, |
||
401 | null, |
||
402 | "Field 'fieldTwo' with value '2' failed filtering, message 'fieldTwo uses fieldOne but fieldOne was" |
||
403 | . " not given.'", |
||
404 | [], |
||
405 | ], |
||
406 | ], |
||
407 | 'returnOnNull filter option' => [ |
||
408 | 'spec' => ['field' => [FilterOptions::RETURN_ON_NULL => true, ['string', true], ['string']]], |
||
409 | 'input' => ['field' => null], |
||
410 | 'options' => [], |
||
411 | 'result' => [true, ['field' => null], null, []], |
||
412 | ], |
||
413 | 'phone alias' => [ |
||
414 | 'spec' => ['field' => [['phone']]], |
||
415 | 'input' => ['field' => '(234) 567 8901'], |
||
416 | 'options' => [], |
||
417 | 'result' => [true, ['field' => '2345678901'], null, []], |
||
418 | ], |
||
419 | 'json alias' => [ |
||
420 | 'spec' => ['field' => [['json']]], |
||
421 | 'input' => ['field' => '{"foo": "bar"}'], |
||
422 | 'options' => [], |
||
423 | 'result' => [true, ['field' => '{"foo": "bar"}'], null, []], |
||
424 | ], |
||
425 | 'json-decode alias' => [ |
||
426 | 'spec' => ['field' => [['json-decode']]], |
||
427 | 'input' => ['field' => '{"foo": "bar"}'], |
||
428 | 'options' => [], |
||
429 | 'result' => [true, ['field' => ['foo' => 'bar']], null, []], |
||
430 | ], |
||
431 | 'xml alias' => [ |
||
432 | 'spec' => ['field' => [['xml']]], |
||
433 | 'input' => ['field' => self::FULL_XML], |
||
434 | 'options' => [], |
||
435 | 'result' => [true, ['field' => self::FULL_XML], null, []], |
||
436 | ], |
||
437 | 'xml-validate alias' => [ |
||
438 | 'spec' => ['field' => [['xml-validate', __DIR__ . '/_files/books.xsd']]], |
||
439 | 'input' => ['field' => self::FULL_XML], |
||
440 | 'options' => [], |
||
441 | 'result' => [true, ['field' => self::FULL_XML], null, []], |
||
442 | ], |
||
443 | 'xml-extract alias' => [ |
||
444 | 'spec' => ['field' => [['xml-extract', "/books/book[@id='bk101']"]]], |
||
445 | 'input' => ['field' => self::FULL_XML], |
||
446 | 'options' => [], |
||
447 | 'result' => [ |
||
448 | true, |
||
449 | [ |
||
450 | 'field' => ('' |
||
451 | . '<book id="bk101">' |
||
452 | . '<author>Gambardella, Matthew</author>' |
||
453 | . "<title>XML Developer's Guide</title>" |
||
454 | . '<genre>Computer</genre>' |
||
455 | . '<price>44.95</price>' |
||
456 | . '<publish_date>2000-10-01</publish_date>' |
||
457 | . '<description>An in-depth look at creating applications with XML.</description>' |
||
458 | . '</book>' |
||
459 | ), |
||
460 | ], |
||
461 | null, |
||
462 | [] |
||
463 | ], |
||
464 | ], |
||
465 | 'array-copy' => [ |
||
466 | 'spec' => [ |
||
467 | 'field' => [['array-copy', ['FOO_VALUE' => 'foo', 'BAR_VALUE' => 'bar']]], |
||
468 | ], |
||
469 | 'input' => ['field' => ['foo' => 'abc', 'bar' => 123]], |
||
470 | 'options' => [], |
||
471 | 'result' => [ |
||
472 | true, |
||
473 | ['field' => ['FOO_VALUE' => 'abc', 'BAR_VALUE' => 123]], |
||
474 | null, |
||
475 | [], |
||
476 | ], |
||
477 | ], |
||
478 | 'array-copy-each' => [ |
||
479 | 'spec' => [ |
||
480 | 'field' => [['array-copy-each', ['FOO_VALUE' => 'foo', 'BAR_VALUE' => 'bar']]], |
||
481 | ], |
||
482 | 'input' => [ |
||
483 | 'field' => [ |
||
484 | ['foo' => 'abc', 'bar' => 123], |
||
485 | ['foo' => 'xyz', 'bar' => 789], |
||
486 | ], |
||
487 | ], |
||
488 | 'options' => [], |
||
489 | 'result' => [ |
||
490 | true, |
||
491 | [ |
||
492 | 'field' => [ |
||
493 | ['FOO_VALUE' => 'abc', 'BAR_VALUE' => 123], |
||
494 | ['FOO_VALUE' => 'xyz', 'BAR_VALUE' => 789], |
||
495 | ], |
||
496 | ], |
||
497 | null, |
||
498 | [], |
||
499 | ], |
||
500 | ], |
||
501 | 'array-pad' => [ |
||
502 | 'spec' => [ |
||
503 | 'field' => [['array-pad', 5, 0, Arrays::ARRAY_PAD_FRONT]], |
||
504 | ], |
||
505 | 'input' => [ |
||
506 | 'field' => ['a', 'b', 'c'], |
||
507 | ], |
||
508 | 'options' => [], |
||
509 | 'result' => [ |
||
510 | true, |
||
511 | [ |
||
512 | 'field' => [0, 0, 'a', 'b', 'c'], |
||
513 | ], |
||
514 | null, |
||
515 | [], |
||
516 | ], |
||
517 | ], |
||
518 | 'time-of-day' => [ |
||
519 | 'spec' => [ |
||
520 | 'field' => [['time-of-day']], |
||
521 | ], |
||
522 | 'input' => [ |
||
523 | 'field' => '23:59:59', |
||
524 | ], |
||
525 | 'options' => [], |
||
526 | 'result' => [ |
||
527 | true, |
||
528 | [ |
||
529 | 'field' => '23:59:59', |
||
530 | ], |
||
531 | null, |
||
532 | [], |
||
533 | ], |
||
534 | ], |
||
535 | 'implode' => [ |
||
536 | 'spec' => [ |
||
537 | 'field' => [['array'], ['implode', ',']], |
||
538 | ], |
||
539 | 'input' => [ |
||
540 | 'field' => ['one', 'two', 'three'], |
||
541 | ], |
||
542 | 'options' => [], |
||
543 | 'result' => [ |
||
544 | true, |
||
545 | [ |
||
546 | 'field' => 'one,two,three', |
||
547 | ], |
||
548 | null, |
||
549 | [], |
||
550 | ], |
||
551 | ], |
||
552 | 'uuid' => [ |
||
553 | 'spec' => [ |
||
554 | 'field' => [['uuid', false, false, [4]]], |
||
555 | ], |
||
556 | 'input' => [ |
||
557 | 'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f', |
||
558 | ], |
||
559 | 'options' => [], |
||
560 | 'result' => [ |
||
561 | true, |
||
562 | [ |
||
563 | 'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f', |
||
564 | ], |
||
565 | null, |
||
566 | [], |
||
567 | ], |
||
568 | ], |
||
569 | 'strip-emoji' => [ |
||
570 | 'spec' => [ |
||
571 | 'field' => [['strip-emoji']], |
||
572 | ], |
||
573 | 'input' => [ |
||
574 | 'field' => 'This 💩 text contains 😞 multiple emoji 🍔 characters 🍚. As well as an alphanumeric ' |
||
575 | . 'supplement 🆗 and flag 🚩', |
||
576 | ], |
||
577 | 'options' => [], |
||
578 | 'result' => [ |
||
579 | true, |
||
580 | [ |
||
581 | 'field' => 'This text contains multiple emoji characters . As well as an alphanumeric ' |
||
582 | . 'supplement and flag ', |
||
583 | ], |
||
584 | null, |
||
585 | [], |
||
586 | ], |
||
1167 |