@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | * @param string $level |
32 | 32 | * @return Assert |
33 | 33 | */ |
34 | -function Assert($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
34 | +function Assert($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
35 | 35 | { |
36 | 36 | $assert = new Assert($value); |
37 | - if ( $fieldName ) |
|
37 | + if ($fieldName) |
|
38 | 38 | { |
39 | 39 | $assert->fieldName($fieldName); |
40 | 40 | } |
41 | - if ( $code ) |
|
41 | + if ($code) |
|
42 | 42 | { |
43 | 43 | $assert->code($code); |
44 | 44 | } |
45 | - if ( $error ) |
|
45 | + if ($error) |
|
46 | 46 | { |
47 | 47 | $assert->error($error); |
48 | 48 | } |
49 | - if ( $level ) |
|
49 | + if ($level) |
|
50 | 50 | { |
51 | 51 | $assert->level($level); |
52 | 52 | } |
@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | * @param string $level |
65 | 65 | * @return Assert |
66 | 66 | */ |
67 | -function Validate($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
67 | +function Validate($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
68 | 68 | { |
69 | - $assert = new Assert($value); |
|
70 | - if ( $fieldName ) |
|
69 | + $assert = new Assert($value); |
|
70 | + if ($fieldName) |
|
71 | 71 | { |
72 | 72 | $assert->fieldName($fieldName); |
73 | 73 | } |
74 | - if ( $code ) |
|
74 | + if ($code) |
|
75 | 75 | { |
76 | 76 | $assert->code($code); |
77 | 77 | } |
78 | - if ( $error ) |
|
78 | + if ($error) |
|
79 | 79 | { |
80 | 80 | $assert->error($error); |
81 | 81 | } |
82 | - if ( $level ) |
|
82 | + if ($level) |
|
83 | 83 | { |
84 | 84 | $assert->level($level); |
85 | 85 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @var string |
138 | 138 | */ |
139 | - protected $exceptionClass = AssertionFailedException::class; |
|
139 | + protected $exceptionClass = AssertionFailedException::class; |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @param mixed $value |
@@ -152,16 +152,16 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public static function runValidators(array $validators) : array |
154 | 154 | { |
155 | - $errors = []; |
|
156 | - foreach ( $validators as $fieldName => $validator ) |
|
155 | + $errors = [ ]; |
|
156 | + foreach ($validators as $fieldName => $validator) |
|
157 | 157 | { |
158 | 158 | try |
159 | 159 | { |
160 | 160 | $validator->__invoke(); |
161 | 161 | } |
162 | - catch ( AssertionFailedException $e ) |
|
162 | + catch (AssertionFailedException $e) |
|
163 | 163 | { |
164 | - $errors[$fieldName] = $e->getMessage(); |
|
164 | + $errors[ $fieldName ] = $e->getMessage(); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -176,22 +176,22 @@ discard block |
||
176 | 176 | * @param string $level |
177 | 177 | * @return Assert |
178 | 178 | */ |
179 | - public static function that($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) : Assert |
|
179 | + public static function that($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) : Assert |
|
180 | 180 | { |
181 | 181 | $assert = new static($value); |
182 | - if ( $fieldName ) |
|
182 | + if ($fieldName) |
|
183 | 183 | { |
184 | 184 | $assert->fieldName($fieldName); |
185 | 185 | } |
186 | - if ( $code ) |
|
186 | + if ($code) |
|
187 | 187 | { |
188 | 188 | $assert->code($code); |
189 | 189 | } |
190 | - if ( $error ) |
|
190 | + if ($error) |
|
191 | 191 | { |
192 | 192 | $assert->error($error); |
193 | 193 | } |
194 | - if ( $level ) |
|
194 | + if ($level) |
|
195 | 195 | { |
196 | 196 | $assert->level($level); |
197 | 197 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param string $level |
271 | 271 | * @return AssertionFailedException |
272 | 272 | */ |
273 | - protected function createException(string $message, int $code, string $fieldName, array $constraints=[], string $level='') : AssertionFailedException |
|
273 | + protected function createException(string $message, int $code, string $fieldName, array $constraints = [ ], string $level = '') : AssertionFailedException |
|
274 | 274 | { |
275 | 275 | $exceptionClass = $this->exceptionClass; |
276 | 276 | $fieldName = empty($fieldName) ? $this->fieldName : $fieldName; |
@@ -372,13 +372,13 @@ discard block |
||
372 | 372 | * @return Assert |
373 | 373 | * @throws AssertionFailedException |
374 | 374 | */ |
375 | - public function eq($value2, string $message='', string $fieldName='') : Assert |
|
375 | + public function eq($value2, string $message = '', string $fieldName = '') : Assert |
|
376 | 376 | { |
377 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
377 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
378 | 378 | { |
379 | 379 | return $this; |
380 | 380 | } |
381 | - if ( $this->value != $value2 ) |
|
381 | + if ($this->value != $value2) |
|
382 | 382 | { |
383 | 383 | $message = $message ?: $this->overrideError; |
384 | 384 | $message = sprintf( |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->stringify($value2) |
388 | 388 | ); |
389 | 389 | |
390 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
390 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | return $this; |
@@ -402,13 +402,13 @@ discard block |
||
402 | 402 | * @return Assert |
403 | 403 | * @throws AssertionFailedException |
404 | 404 | */ |
405 | - public function greaterThan($value2, string $message='', string $fieldName='') : Assert |
|
405 | + public function greaterThan($value2, string $message = '', string $fieldName = '') : Assert |
|
406 | 406 | { |
407 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
407 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
408 | 408 | { |
409 | 409 | return $this; |
410 | 410 | } |
411 | - if ( ! ( $this->value > $value2 ) ) |
|
411 | + if ( ! ($this->value > $value2)) |
|
412 | 412 | { |
413 | 413 | $message = $message ?: $this->overrideError; |
414 | 414 | $message = sprintf( |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $this->stringify($value2) |
418 | 418 | ); |
419 | 419 | |
420 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
420 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | return $this; |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | * @return Assert |
433 | 433 | * @throws AssertionFailedException |
434 | 434 | */ |
435 | - public function greaterThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
435 | + public function greaterThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
436 | 436 | { |
437 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
437 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
438 | 438 | { |
439 | 439 | return $this; |
440 | 440 | } |
441 | - if ( ! ( $this->value >= $value2 ) ) |
|
441 | + if ( ! ($this->value >= $value2)) |
|
442 | 442 | { |
443 | 443 | $message = $message ?: $this->overrideError; |
444 | 444 | $message = sprintf( |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | $this->stringify($value2) |
448 | 448 | ); |
449 | 449 | |
450 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
450 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | return $this; |
@@ -462,13 +462,13 @@ discard block |
||
462 | 462 | * @return Assert |
463 | 463 | * @throws AssertionFailedException |
464 | 464 | */ |
465 | - public function lessThan($value2, string $message='', string $fieldName='') : Assert |
|
465 | + public function lessThan($value2, string $message = '', string $fieldName = '') : Assert |
|
466 | 466 | { |
467 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
467 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
468 | 468 | { |
469 | 469 | return $this; |
470 | 470 | } |
471 | - if ( ! ( $this->value < $value2 ) ) |
|
471 | + if ( ! ($this->value < $value2)) |
|
472 | 472 | { |
473 | 473 | $message = $message ?: $this->overrideError; |
474 | 474 | $message = sprintf( |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $this->stringify($value2) |
478 | 478 | ); |
479 | 479 | |
480 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, ['expected' => $value2]); |
|
480 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, [ 'expected' => $value2 ]); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | return $this; |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | * @return Assert |
493 | 493 | * @throws AssertionFailedException |
494 | 494 | */ |
495 | - public function lessThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
495 | + public function lessThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
496 | 496 | { |
497 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
497 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
498 | 498 | { |
499 | 499 | return $this; |
500 | 500 | } |
501 | - if ( ! ( $this->value <= $value2 ) ) |
|
501 | + if ( ! ($this->value <= $value2)) |
|
502 | 502 | { |
503 | 503 | $message = $message ?: $this->overrideError; |
504 | 504 | $message = sprintf( |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $this->stringify($value2) |
508 | 508 | ); |
509 | 509 | |
510 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, ['expected' => $value2]); |
|
510 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return $this; |
@@ -522,13 +522,13 @@ discard block |
||
522 | 522 | * @return Assert |
523 | 523 | * @throws AssertionFailedException |
524 | 524 | */ |
525 | - public function same($value2, string $message='', string $fieldName='') : Assert |
|
525 | + public function same($value2, string $message = '', string $fieldName = '') : Assert |
|
526 | 526 | { |
527 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
527 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
528 | 528 | { |
529 | 529 | return $this; |
530 | 530 | } |
531 | - if ( $this->value !== $value2 ) |
|
531 | + if ($this->value !== $value2) |
|
532 | 532 | { |
533 | 533 | $message = $message ?: $this->overrideError; |
534 | 534 | $message = sprintf( |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $this->stringify($value2) |
538 | 538 | ); |
539 | 539 | |
540 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, ['expected' => $value2]); |
|
540 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | return $this; |
@@ -552,13 +552,13 @@ discard block |
||
552 | 552 | * @return Assert |
553 | 553 | * @throws AssertionFailedException |
554 | 554 | */ |
555 | - public function notEq($value2, string $message='', string $fieldName='') : Assert |
|
555 | + public function notEq($value2, string $message = '', string $fieldName = '') : Assert |
|
556 | 556 | { |
557 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
557 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
558 | 558 | { |
559 | 559 | return $this; |
560 | 560 | } |
561 | - if ( $this->value == $value2 ) |
|
561 | + if ($this->value == $value2) |
|
562 | 562 | { |
563 | 563 | $message = $message ?: $this->overrideError; |
564 | 564 | $message = sprintf( |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | $this->stringify($value2) |
568 | 568 | ); |
569 | 569 | |
570 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, ['expected' => $value2]); |
|
570 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | return $this; |
@@ -581,13 +581,13 @@ discard block |
||
581 | 581 | * @return Assert |
582 | 582 | * @throws AssertionFailedException |
583 | 583 | */ |
584 | - public function isCallable(string $message='', string $fieldName='') : Assert |
|
584 | + public function isCallable(string $message = '', string $fieldName = '') : Assert |
|
585 | 585 | { |
586 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
586 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
587 | 587 | { |
588 | 588 | return $this; |
589 | 589 | } |
590 | - if ( !is_callable($this->value) ) |
|
590 | + if ( ! is_callable($this->value)) |
|
591 | 591 | { |
592 | 592 | $message = $message ?: $this->overrideError; |
593 | 593 | $message = sprintf( |
@@ -610,13 +610,13 @@ discard block |
||
610 | 610 | * @return Assert |
611 | 611 | * @throws AssertionFailedException |
612 | 612 | */ |
613 | - public function notSame($value2, string $message='', string $fieldName='') : Assert |
|
613 | + public function notSame($value2, string $message = '', string $fieldName = '') : Assert |
|
614 | 614 | { |
615 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
615 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
616 | 616 | { |
617 | 617 | return $this; |
618 | 618 | } |
619 | - if ( $this->value === $value2 ) |
|
619 | + if ($this->value === $value2) |
|
620 | 620 | { |
621 | 621 | $message = $message ?: $this->overrideError; |
622 | 622 | $message = sprintf( |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | $this->stringify($value2) |
626 | 626 | ); |
627 | 627 | |
628 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, ['expected' => $value2]); |
|
628 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | return $this; |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | * @return Assert |
640 | 640 | * @throws AssertionFailedException |
641 | 641 | */ |
642 | - public function id(string $message='', string $fieldName='') : Assert |
|
642 | + public function id(string $message = '', string $fieldName = '') : Assert |
|
643 | 643 | { |
644 | 644 | $message = $message ?: $this->overrideError; |
645 | 645 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | * @return Assert |
655 | 655 | * @throws AssertionFailedException |
656 | 656 | */ |
657 | - public function unsignedInt(string $message='', string $fieldName='') : Assert |
|
657 | + public function unsignedInt(string $message = '', string $fieldName = '') : Assert |
|
658 | 658 | { |
659 | 659 | $message = $message ?: $this->overrideError; |
660 | 660 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * @return Assert |
671 | 671 | * @throws AssertionFailedException |
672 | 672 | */ |
673 | - public function flag(string $message='', string $fieldName='') : Assert |
|
673 | + public function flag(string $message = '', string $fieldName = '') : Assert |
|
674 | 674 | { |
675 | 675 | $message = $message ?: $this->overrideError; |
676 | 676 | $message = $message ?: 'Value "%s" is not a 0 or 1.'; |
@@ -686,12 +686,12 @@ discard block |
||
686 | 686 | * @return Assert |
687 | 687 | * @throws AssertionFailedException |
688 | 688 | */ |
689 | - public function status(string $message='', string $fieldName='') : Assert |
|
689 | + public function status(string $message = '', string $fieldName = '') : Assert |
|
690 | 690 | { |
691 | 691 | $message = $message ?: $this->overrideError; |
692 | 692 | $message = $message ?: 'Value "%s" is not a valid status.'; |
693 | 693 | |
694 | - return $this->integer($message, $fieldName)->inArray([-1, 0, 1]); |
|
694 | + return $this->integer($message, $fieldName)->inArray([-1, 0, 1 ]); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * @return Assert |
703 | 703 | * @throws AssertionFailedException |
704 | 704 | */ |
705 | - public function nullOrId(string $message='', string $fieldName='') : Assert |
|
705 | + public function nullOrId(string $message = '', string $fieldName = '') : Assert |
|
706 | 706 | { |
707 | 707 | return $this->nullOr()->id($message, $fieldName); |
708 | 708 | } |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @return Assert |
716 | 716 | * @throws AssertionFailedException |
717 | 717 | */ |
718 | - public function allIds(string $message='', string $fieldName='') : Assert |
|
718 | + public function allIds(string $message = '', string $fieldName = '') : Assert |
|
719 | 719 | { |
720 | 720 | return $this->all()->id($message, $fieldName); |
721 | 721 | } |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @return Assert |
729 | 729 | * @throws AssertionFailedException |
730 | 730 | */ |
731 | - public function int(string $message='', string $fieldName='') : Assert |
|
731 | + public function int(string $message = '', string $fieldName = '') : Assert |
|
732 | 732 | { |
733 | 733 | return $this->integer($message, $fieldName); |
734 | 734 | } |
@@ -741,13 +741,13 @@ discard block |
||
741 | 741 | * @return Assert |
742 | 742 | * @throws AssertionFailedException |
743 | 743 | */ |
744 | - public function integer(string $message='', string $fieldName='') : Assert |
|
744 | + public function integer(string $message = '', string $fieldName = '') : Assert |
|
745 | 745 | { |
746 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
746 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
747 | 747 | { |
748 | 748 | return $this; |
749 | 749 | } |
750 | - if ( !is_int($this->value) ) |
|
750 | + if ( ! is_int($this->value)) |
|
751 | 751 | { |
752 | 752 | $message = $message ?: $this->overrideError; |
753 | 753 | $message = sprintf( |
@@ -769,13 +769,13 @@ discard block |
||
769 | 769 | * @return Assert |
770 | 770 | * @throws AssertionFailedException |
771 | 771 | */ |
772 | - public function float(string $message='', string $fieldName='') : Assert |
|
772 | + public function float(string $message = '', string $fieldName = '') : Assert |
|
773 | 773 | { |
774 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
774 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
775 | 775 | { |
776 | 776 | return $this; |
777 | 777 | } |
778 | - if ( ! is_float($this->value) ) |
|
778 | + if ( ! is_float($this->value)) |
|
779 | 779 | { |
780 | 780 | $message = $message ?: $this->overrideError; |
781 | 781 | $message = sprintf( |
@@ -797,13 +797,13 @@ discard block |
||
797 | 797 | * @return Assert |
798 | 798 | * @throws AssertionFailedException |
799 | 799 | */ |
800 | - public function digit(string $message='', string $fieldName='') : Assert |
|
800 | + public function digit(string $message = '', string $fieldName = '') : Assert |
|
801 | 801 | { |
802 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
802 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
803 | 803 | { |
804 | 804 | return $this; |
805 | 805 | } |
806 | - if ( ! ctype_digit((string)$this->value) ) |
|
806 | + if ( ! ctype_digit((string)$this->value)) |
|
807 | 807 | { |
808 | 808 | $message = $message ?: $this->overrideError; |
809 | 809 | $message = sprintf( |
@@ -825,18 +825,18 @@ discard block |
||
825 | 825 | * @return Assert |
826 | 826 | * @throws AssertionFailedException |
827 | 827 | */ |
828 | - public function date(string $message='', string $fieldName='') : Assert |
|
828 | + public function date(string $message = '', string $fieldName = '') : Assert |
|
829 | 829 | { |
830 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
830 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
831 | 831 | { |
832 | 832 | return $this; |
833 | 833 | } |
834 | 834 | $this->notEmpty($message, $fieldName); |
835 | - if ( $this->value instanceof \DateTime ) |
|
835 | + if ($this->value instanceof \DateTime) |
|
836 | 836 | { |
837 | 837 | return $this; |
838 | 838 | } |
839 | - if ( strtotime($this->value) === false ) |
|
839 | + if (strtotime($this->value) === false) |
|
840 | 840 | { |
841 | 841 | $message = $message ?: $this->overrideError; |
842 | 842 | $message = sprintf( |
@@ -857,14 +857,14 @@ discard block |
||
857 | 857 | * @return $this |
858 | 858 | * @throws AssertionFailedException |
859 | 859 | */ |
860 | - public function after($afterDate, string $message='', string $fieldName='') |
|
860 | + public function after($afterDate, string $message = '', string $fieldName = '') |
|
861 | 861 | { |
862 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
862 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
863 | 863 | { |
864 | 864 | return $this; |
865 | 865 | } |
866 | 866 | $this->notEmpty($message, $fieldName); |
867 | - if ( strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate) ) |
|
867 | + if (strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate)) |
|
868 | 868 | { |
869 | 869 | $message = $message ?: $this->overrideError; |
870 | 870 | $message = sprintf( |
@@ -886,13 +886,13 @@ discard block |
||
886 | 886 | * @return Assert |
887 | 887 | * @throws AssertionFailedException |
888 | 888 | */ |
889 | - public function integerish(string $message='', string $fieldName='') : Assert |
|
889 | + public function integerish(string $message = '', string $fieldName = '') : Assert |
|
890 | 890 | { |
891 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
891 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
892 | 892 | { |
893 | 893 | return $this; |
894 | 894 | } |
895 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
895 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
896 | 896 | { |
897 | 897 | $message = $message ?: $this->overrideError; |
898 | 898 | $message = sprintf( |
@@ -914,13 +914,13 @@ discard block |
||
914 | 914 | * @return Assert |
915 | 915 | * @throws AssertionFailedException |
916 | 916 | */ |
917 | - public function boolean(string $message='', string $fieldName='') : Assert |
|
917 | + public function boolean(string $message = '', string $fieldName = '') : Assert |
|
918 | 918 | { |
919 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
919 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
920 | 920 | { |
921 | 921 | return $this; |
922 | 922 | } |
923 | - if ( ! is_bool($this->value) ) |
|
923 | + if ( ! is_bool($this->value)) |
|
924 | 924 | { |
925 | 925 | $message = $message ?: $this->overrideError; |
926 | 926 | $message = sprintf( |
@@ -942,13 +942,13 @@ discard block |
||
942 | 942 | * @return Assert |
943 | 943 | * @throws AssertionFailedException |
944 | 944 | */ |
945 | - public function scalar(string $message='', string $fieldName='') : Assert |
|
945 | + public function scalar(string $message = '', string $fieldName = '') : Assert |
|
946 | 946 | { |
947 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
947 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
948 | 948 | { |
949 | 949 | return $this; |
950 | 950 | } |
951 | - if ( ! is_scalar($this->value) ) |
|
951 | + if ( ! is_scalar($this->value)) |
|
952 | 952 | { |
953 | 953 | $message = $message ?: $this->overrideError; |
954 | 954 | $message = sprintf( |
@@ -970,13 +970,13 @@ discard block |
||
970 | 970 | * @return Assert |
971 | 971 | * @throws AssertionFailedException |
972 | 972 | */ |
973 | - public function notEmpty(string $message='', string $fieldName='') : Assert |
|
973 | + public function notEmpty(string $message = '', string $fieldName = '') : Assert |
|
974 | 974 | { |
975 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
975 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
976 | 976 | { |
977 | 977 | return $this; |
978 | 978 | } |
979 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
979 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
980 | 980 | { |
981 | 981 | $message = $message ?: $this->overrideError; |
982 | 982 | $message = sprintf( |
@@ -998,13 +998,13 @@ discard block |
||
998 | 998 | * @return Assert |
999 | 999 | * @throws AssertionFailedException |
1000 | 1000 | */ |
1001 | - public function noContent(string $message='', string $fieldName='') : Assert |
|
1001 | + public function noContent(string $message = '', string $fieldName = '') : Assert |
|
1002 | 1002 | { |
1003 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1003 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1004 | 1004 | { |
1005 | 1005 | return $this; |
1006 | 1006 | } |
1007 | - if ( !empty( $this->value ) ) |
|
1007 | + if ( ! empty($this->value)) |
|
1008 | 1008 | { |
1009 | 1009 | $message = $message ?: $this->overrideError; |
1010 | 1010 | $message = sprintf( |
@@ -1026,13 +1026,13 @@ discard block |
||
1026 | 1026 | * @return Assert |
1027 | 1027 | * @throws AssertionFailedException |
1028 | 1028 | */ |
1029 | - public function notNull(string $message='', string $fieldName='') : Assert |
|
1029 | + public function notNull(string $message = '', string $fieldName = '') : Assert |
|
1030 | 1030 | { |
1031 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1031 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1032 | 1032 | { |
1033 | 1033 | return $this; |
1034 | 1034 | } |
1035 | - if ( $this->value === null ) |
|
1035 | + if ($this->value === null) |
|
1036 | 1036 | { |
1037 | 1037 | $message = $message ?: $this->overrideError; |
1038 | 1038 | $message = sprintf( |
@@ -1054,13 +1054,13 @@ discard block |
||
1054 | 1054 | * @return Assert |
1055 | 1055 | * @throws AssertionFailedException |
1056 | 1056 | */ |
1057 | - public function string(string $message='', string $fieldName='') : Assert |
|
1057 | + public function string(string $message = '', string $fieldName = '') : Assert |
|
1058 | 1058 | { |
1059 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1059 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1060 | 1060 | { |
1061 | 1061 | return $this; |
1062 | 1062 | } |
1063 | - if ( !is_string($this->value) ) |
|
1063 | + if ( ! is_string($this->value)) |
|
1064 | 1064 | { |
1065 | 1065 | $message = $message ?: $this->overrideError; |
1066 | 1066 | $message = sprintf( |
@@ -1084,14 +1084,14 @@ discard block |
||
1084 | 1084 | * @return Assert |
1085 | 1085 | * @throws AssertionFailedException |
1086 | 1086 | */ |
1087 | - public function regex(string $pattern, string $message='', string $fieldName='') : Assert |
|
1087 | + public function regex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
1088 | 1088 | { |
1089 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1089 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1090 | 1090 | { |
1091 | 1091 | return $this; |
1092 | 1092 | } |
1093 | 1093 | $this->string($message, $fieldName); |
1094 | - if ( ! preg_match($pattern, $this->value) ) |
|
1094 | + if ( ! preg_match($pattern, $this->value)) |
|
1095 | 1095 | { |
1096 | 1096 | $message = $message ?: $this->overrideError; |
1097 | 1097 | $message = sprintf( |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $this->stringify($this->value) |
1100 | 1100 | ); |
1101 | 1101 | |
1102 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
1102 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | return $this; |
@@ -1113,15 +1113,15 @@ discard block |
||
1113 | 1113 | * @return Assert |
1114 | 1114 | * @throws AssertionFailedException |
1115 | 1115 | */ |
1116 | - public function ipAddress(string $message='', string $fieldName='') : Assert |
|
1116 | + public function ipAddress(string $message = '', string $fieldName = '') : Assert |
|
1117 | 1117 | { |
1118 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1118 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1119 | 1119 | { |
1120 | 1120 | return $this; |
1121 | 1121 | } |
1122 | 1122 | $this->string($message, $fieldName); |
1123 | - $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
1124 | - if ( ! preg_match($pattern, $this->value) ) |
|
1123 | + $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
1124 | + if ( ! preg_match($pattern, $this->value)) |
|
1125 | 1125 | { |
1126 | 1126 | $message = $message ?: $this->overrideError; |
1127 | 1127 | $message = sprintf( |
@@ -1144,14 +1144,14 @@ discard block |
||
1144 | 1144 | * @return Assert |
1145 | 1145 | * @throws AssertionFailedException |
1146 | 1146 | */ |
1147 | - public function notRegex(string $pattern, string $message='', string $fieldName='') : Assert |
|
1147 | + public function notRegex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
1148 | 1148 | { |
1149 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1149 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1150 | 1150 | { |
1151 | 1151 | return $this; |
1152 | 1152 | } |
1153 | 1153 | $this->string($message, $fieldName); |
1154 | - if ( preg_match($pattern, $this->value) ) |
|
1154 | + if (preg_match($pattern, $this->value)) |
|
1155 | 1155 | { |
1156 | 1156 | $message = $message ?: $this->overrideError; |
1157 | 1157 | $message = sprintf( |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | $this->stringify($this->value) |
1160 | 1160 | ); |
1161 | 1161 | |
1162 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
1162 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | return $this; |
@@ -1175,14 +1175,14 @@ discard block |
||
1175 | 1175 | * @return Assert |
1176 | 1176 | * @throws AssertionFailedException |
1177 | 1177 | */ |
1178 | - public function length(int $length, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1178 | + public function length(int $length, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1179 | 1179 | { |
1180 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1180 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1181 | 1181 | { |
1182 | 1182 | return $this; |
1183 | 1183 | } |
1184 | 1184 | $this->string($message, $fieldName); |
1185 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
1185 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
1186 | 1186 | { |
1187 | 1187 | $message = $message ?: $this->overrideError; |
1188 | 1188 | $message = sprintf( |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | $length, |
1192 | 1192 | mb_strlen($this->value, $encoding) |
1193 | 1193 | ); |
1194 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
1194 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
1195 | 1195 | |
1196 | 1196 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $fieldName, $constraints); |
1197 | 1197 | } |
@@ -1210,24 +1210,24 @@ discard block |
||
1210 | 1210 | * @return Assert |
1211 | 1211 | * @throws AssertionFailedException |
1212 | 1212 | */ |
1213 | - public function minLength(int $minLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1213 | + public function minLength(int $minLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1214 | 1214 | { |
1215 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1215 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1216 | 1216 | { |
1217 | 1217 | return $this; |
1218 | 1218 | } |
1219 | 1219 | $this->string($message, $fieldName); |
1220 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1220 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1221 | 1221 | { |
1222 | 1222 | $message = $message ?: $this->overrideError; |
1223 | - $message = sprintf( |
|
1223 | + $message = sprintf( |
|
1224 | 1224 | $message |
1225 | 1225 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1226 | 1226 | $this->stringify($this->value), |
1227 | 1227 | $minLength, |
1228 | 1228 | mb_strlen($this->value, $encoding) |
1229 | 1229 | ); |
1230 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1230 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1231 | 1231 | |
1232 | 1232 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
1233 | 1233 | } |
@@ -1246,23 +1246,23 @@ discard block |
||
1246 | 1246 | * @return Assert |
1247 | 1247 | * @throws AssertionFailedException |
1248 | 1248 | */ |
1249 | - public function maxLength(int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1249 | + public function maxLength(int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1250 | 1250 | { |
1251 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1251 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1252 | 1252 | { |
1253 | 1253 | return $this; |
1254 | 1254 | } |
1255 | 1255 | $this->string($message, $fieldName); |
1256 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1256 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1257 | 1257 | { |
1258 | 1258 | $message = $message ?: $this->overrideError; |
1259 | - $message = sprintf( |
|
1259 | + $message = sprintf( |
|
1260 | 1260 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1261 | 1261 | $this->stringify($this->value), |
1262 | 1262 | $maxLength, |
1263 | 1263 | mb_strlen($this->value, $encoding) |
1264 | 1264 | ); |
1265 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1265 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1266 | 1266 | |
1267 | 1267 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
1268 | 1268 | } |
@@ -1281,37 +1281,37 @@ discard block |
||
1281 | 1281 | * @return Assert |
1282 | 1282 | * @throws AssertionFailedException |
1283 | 1283 | */ |
1284 | - public function betweenLength(int $minLength, int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1284 | + public function betweenLength(int $minLength, int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1285 | 1285 | { |
1286 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1286 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1287 | 1287 | { |
1288 | 1288 | return $this; |
1289 | 1289 | } |
1290 | 1290 | $this->string($message, $fieldName); |
1291 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1291 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1292 | 1292 | { |
1293 | 1293 | $message = $message ?: $this->overrideError; |
1294 | - $message = sprintf( |
|
1294 | + $message = sprintf( |
|
1295 | 1295 | $message |
1296 | 1296 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1297 | 1297 | $this->stringify($this->value), |
1298 | 1298 | $minLength, |
1299 | 1299 | mb_strlen($this->value, $encoding) |
1300 | 1300 | ); |
1301 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1301 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1302 | 1302 | |
1303 | 1303 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
1304 | 1304 | } |
1305 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1305 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1306 | 1306 | { |
1307 | 1307 | $message = $message ?: $this->overrideError; |
1308 | - $message = sprintf( |
|
1308 | + $message = sprintf( |
|
1309 | 1309 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1310 | 1310 | $this->stringify($this->value), |
1311 | 1311 | $maxLength, |
1312 | 1312 | mb_strlen($this->value, $encoding) |
1313 | 1313 | ); |
1314 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1314 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1315 | 1315 | |
1316 | 1316 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
1317 | 1317 | } |
@@ -1329,22 +1329,22 @@ discard block |
||
1329 | 1329 | * @return Assert |
1330 | 1330 | * @throws AssertionFailedException |
1331 | 1331 | */ |
1332 | - public function startsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1332 | + public function startsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1333 | 1333 | { |
1334 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1334 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1335 | 1335 | { |
1336 | 1336 | return $this; |
1337 | 1337 | } |
1338 | 1338 | $this->string($message, $fieldName); |
1339 | - if ( mb_strpos($this->value, $needle, 0, $encoding) !== 0 ) |
|
1339 | + if (mb_strpos($this->value, $needle, 0, $encoding) !== 0) |
|
1340 | 1340 | { |
1341 | 1341 | $message = $message ?: $this->overrideError; |
1342 | - $message = sprintf( |
|
1342 | + $message = sprintf( |
|
1343 | 1343 | $message ?: 'Value "%s" does not start with "%s".', |
1344 | 1344 | $this->stringify($this->value), |
1345 | 1345 | $this->stringify($needle) |
1346 | 1346 | ); |
1347 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1347 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1348 | 1348 | |
1349 | 1349 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $fieldName, $constraints); |
1350 | 1350 | } |
@@ -1362,23 +1362,23 @@ discard block |
||
1362 | 1362 | * @return Assert |
1363 | 1363 | * @throws AssertionFailedException |
1364 | 1364 | */ |
1365 | - public function endsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1365 | + public function endsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1366 | 1366 | { |
1367 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1367 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1368 | 1368 | { |
1369 | 1369 | return $this; |
1370 | 1370 | } |
1371 | 1371 | $this->string($message, $fieldName); |
1372 | 1372 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
1373 | - if ( mb_strripos($this->value, $needle, 0 , $encoding) !== $stringPosition ) |
|
1373 | + if (mb_strripos($this->value, $needle, 0, $encoding) !== $stringPosition) |
|
1374 | 1374 | { |
1375 | 1375 | $message = $message ?: $this->overrideError; |
1376 | - $message = sprintf( |
|
1376 | + $message = sprintf( |
|
1377 | 1377 | $message ?: 'Value "%s" does not end with "%s".', |
1378 | 1378 | $this->stringify($this->value), |
1379 | 1379 | $this->stringify($needle) |
1380 | 1380 | ); |
1381 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1381 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1382 | 1382 | |
1383 | 1383 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $fieldName, $constraints); |
1384 | 1384 | } |
@@ -1396,22 +1396,22 @@ discard block |
||
1396 | 1396 | * @return Assert |
1397 | 1397 | * @throws AssertionFailedException |
1398 | 1398 | */ |
1399 | - public function contains(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
1399 | + public function contains(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
1400 | 1400 | { |
1401 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1401 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1402 | 1402 | { |
1403 | 1403 | return $this; |
1404 | 1404 | } |
1405 | 1405 | $this->string($message, $fieldName); |
1406 | - if ( mb_strpos($this->value, $needle, 0, $encoding) === false ) |
|
1406 | + if (mb_strpos($this->value, $needle, 0, $encoding) === false) |
|
1407 | 1407 | { |
1408 | 1408 | $message = $message ?: $this->overrideError; |
1409 | - $message = sprintf( |
|
1409 | + $message = sprintf( |
|
1410 | 1410 | $message ?: 'Value "%s" does not contain "%s".', |
1411 | 1411 | $this->stringify($this->value), |
1412 | 1412 | $this->stringify($needle) |
1413 | 1413 | ); |
1414 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1414 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1415 | 1415 | |
1416 | 1416 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $fieldName, $constraints); |
1417 | 1417 | } |
@@ -1428,13 +1428,13 @@ discard block |
||
1428 | 1428 | * @return Assert |
1429 | 1429 | * @throws AssertionFailedException |
1430 | 1430 | */ |
1431 | - public function choice(array $choices, string $message='', string $fieldName='') : Assert |
|
1431 | + public function choice(array $choices, string $message = '', string $fieldName = '') : Assert |
|
1432 | 1432 | { |
1433 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1433 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1434 | 1434 | { |
1435 | 1435 | return $this; |
1436 | 1436 | } |
1437 | - if ( !in_array($this->value, $choices, true) ) |
|
1437 | + if ( ! in_array($this->value, $choices, true)) |
|
1438 | 1438 | { |
1439 | 1439 | $message = $message ?: $this->overrideError; |
1440 | 1440 | $message = sprintf( |
@@ -1443,7 +1443,7 @@ discard block |
||
1443 | 1443 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
1444 | 1444 | ); |
1445 | 1445 | |
1446 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, ['choices' => $choices]); |
|
1446 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, [ 'choices' => $choices ]); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | return $this; |
@@ -1458,9 +1458,9 @@ discard block |
||
1458 | 1458 | * @return Assert |
1459 | 1459 | * @throws AssertionFailedException |
1460 | 1460 | */ |
1461 | - public function inArray(array $choices, string $message='', string $fieldName='') : Assert |
|
1461 | + public function inArray(array $choices, string $message = '', string $fieldName = '') : Assert |
|
1462 | 1462 | { |
1463 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1463 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1464 | 1464 | { |
1465 | 1465 | return $this; |
1466 | 1466 | } |
@@ -1477,13 +1477,13 @@ discard block |
||
1477 | 1477 | * @return Assert |
1478 | 1478 | * @throws AssertionFailedException |
1479 | 1479 | */ |
1480 | - public function numeric(string $message='', string $fieldName='') : Assert |
|
1480 | + public function numeric(string $message = '', string $fieldName = '') : Assert |
|
1481 | 1481 | { |
1482 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1482 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1483 | 1483 | { |
1484 | 1484 | return $this; |
1485 | 1485 | } |
1486 | - if ( ! is_numeric($this->value) ) |
|
1486 | + if ( ! is_numeric($this->value)) |
|
1487 | 1487 | { |
1488 | 1488 | $message = $message ?: $this->overrideError; |
1489 | 1489 | $message = sprintf( |
@@ -1505,7 +1505,7 @@ discard block |
||
1505 | 1505 | * @return Assert |
1506 | 1506 | * @throws AssertionFailedException |
1507 | 1507 | */ |
1508 | - public function nonEmptyArray(string $message='', string $fieldName='') : Assert |
|
1508 | + public function nonEmptyArray(string $message = '', string $fieldName = '') : Assert |
|
1509 | 1509 | { |
1510 | 1510 | $message = $message ?: 'Value "%s" is not a non-empty array.'; |
1511 | 1511 | |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | * @return Assert |
1521 | 1521 | * @throws AssertionFailedException |
1522 | 1522 | */ |
1523 | - public function nonEmptyInt(string $message='', string $fieldName='') : Assert |
|
1523 | + public function nonEmptyInt(string $message = '', string $fieldName = '') : Assert |
|
1524 | 1524 | { |
1525 | 1525 | $message = $message ?: 'Value "%s" is not a non-empty integer.'; |
1526 | 1526 | |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | * @return Assert |
1536 | 1536 | * @throws AssertionFailedException |
1537 | 1537 | */ |
1538 | - public function nonEmptyString(string $message='', string $fieldName='') : Assert |
|
1538 | + public function nonEmptyString(string $message = '', string $fieldName = '') : Assert |
|
1539 | 1539 | { |
1540 | 1540 | $message = $message ?: 'Value "%s" is not a non-empty string.'; |
1541 | 1541 | |
@@ -1550,13 +1550,13 @@ discard block |
||
1550 | 1550 | * @return Assert |
1551 | 1551 | * @throws AssertionFailedException |
1552 | 1552 | */ |
1553 | - public function isArray(string $message='', string $fieldName='') : Assert |
|
1553 | + public function isArray(string $message = '', string $fieldName = '') : Assert |
|
1554 | 1554 | { |
1555 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1555 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1556 | 1556 | { |
1557 | 1557 | return $this; |
1558 | 1558 | } |
1559 | - if ( !is_array($this->value) ) |
|
1559 | + if ( ! is_array($this->value)) |
|
1560 | 1560 | { |
1561 | 1561 | $message = $message ?: $this->overrideError; |
1562 | 1562 | $message = sprintf( |
@@ -1578,13 +1578,13 @@ discard block |
||
1578 | 1578 | * @return Assert |
1579 | 1579 | * @throws AssertionFailedException |
1580 | 1580 | */ |
1581 | - public function isTraversable(string $message='', string $fieldName='') : Assert |
|
1581 | + public function isTraversable(string $message = '', string $fieldName = '') : Assert |
|
1582 | 1582 | { |
1583 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1583 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1584 | 1584 | { |
1585 | 1585 | return $this; |
1586 | 1586 | } |
1587 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
1587 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
1588 | 1588 | { |
1589 | 1589 | $message = $message ?: $this->overrideError; |
1590 | 1590 | $message = sprintf( |
@@ -1606,13 +1606,13 @@ discard block |
||
1606 | 1606 | * @return Assert |
1607 | 1607 | * @throws AssertionFailedException |
1608 | 1608 | */ |
1609 | - public function isArrayAccessible(string $message='', string $fieldName='') : Assert |
|
1609 | + public function isArrayAccessible(string $message = '', string $fieldName = '') : Assert |
|
1610 | 1610 | { |
1611 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1611 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1612 | 1612 | { |
1613 | 1613 | return $this; |
1614 | 1614 | } |
1615 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
1615 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
1616 | 1616 | { |
1617 | 1617 | $message = $message ?: $this->overrideError; |
1618 | 1618 | $message = sprintf( |
@@ -1635,14 +1635,14 @@ discard block |
||
1635 | 1635 | * @return Assert |
1636 | 1636 | * @throws AssertionFailedException |
1637 | 1637 | */ |
1638 | - public function keyExists($key, string $message='', string $fieldName='') : Assert |
|
1638 | + public function keyExists($key, string $message = '', string $fieldName = '') : Assert |
|
1639 | 1639 | { |
1640 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1640 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1641 | 1641 | { |
1642 | 1642 | return $this; |
1643 | 1643 | } |
1644 | 1644 | $this->isArray($message, $fieldName); |
1645 | - if ( !array_key_exists($key, $this->value) ) |
|
1645 | + if ( ! array_key_exists($key, $this->value)) |
|
1646 | 1646 | { |
1647 | 1647 | $message = $message ?: $this->overrideError; |
1648 | 1648 | $message = sprintf( |
@@ -1650,7 +1650,7 @@ discard block |
||
1650 | 1650 | $this->stringify($key) |
1651 | 1651 | ); |
1652 | 1652 | |
1653 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, ['key' => $key]); |
|
1653 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
1654 | 1654 | } |
1655 | 1655 | |
1656 | 1656 | return $this; |
@@ -1665,23 +1665,23 @@ discard block |
||
1665 | 1665 | * @return Assert |
1666 | 1666 | * @throws AssertionFailedException |
1667 | 1667 | */ |
1668 | - public function keysExist(array $keys, string $message='', string $fieldName='') : Assert |
|
1668 | + public function keysExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
1669 | 1669 | { |
1670 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1670 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1671 | 1671 | { |
1672 | 1672 | return $this; |
1673 | 1673 | } |
1674 | 1674 | $this->isArray($message, $fieldName); |
1675 | - foreach ( $keys as $key ) |
|
1675 | + foreach ($keys as $key) |
|
1676 | 1676 | { |
1677 | - if ( !array_key_exists($key, $this->value) ) |
|
1677 | + if ( ! array_key_exists($key, $this->value)) |
|
1678 | 1678 | { |
1679 | 1679 | $message = $message |
1680 | 1680 | ?: sprintf( |
1681 | 1681 | 'Array does not contain an element with key "%s"', |
1682 | 1682 | $this->stringify($key) |
1683 | 1683 | ); |
1684 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, ['key' => $key]); |
|
1684 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, [ 'key' => $key ]); |
|
1685 | 1685 | } |
1686 | 1686 | } |
1687 | 1687 | |
@@ -1697,14 +1697,14 @@ discard block |
||
1697 | 1697 | * @return Assert |
1698 | 1698 | * @throws AssertionFailedException |
1699 | 1699 | */ |
1700 | - public function propertyExists($key, string $message='', string $fieldName='') : Assert |
|
1700 | + public function propertyExists($key, string $message = '', string $fieldName = '') : Assert |
|
1701 | 1701 | { |
1702 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1702 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1703 | 1703 | { |
1704 | 1704 | return $this; |
1705 | 1705 | } |
1706 | 1706 | $this->isObject($message, $fieldName); |
1707 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1707 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1708 | 1708 | { |
1709 | 1709 | $message = $message |
1710 | 1710 | ?: sprintf( |
@@ -1712,7 +1712,7 @@ discard block |
||
1712 | 1712 | $this->stringify($key) |
1713 | 1713 | ); |
1714 | 1714 | |
1715 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, ['key' => $key]); |
|
1715 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | return $this; |
@@ -1727,24 +1727,24 @@ discard block |
||
1727 | 1727 | * @return Assert |
1728 | 1728 | * @throws AssertionFailedException |
1729 | 1729 | */ |
1730 | - public function propertiesExist(array $keys, string $message='', string $fieldName='') : Assert |
|
1730 | + public function propertiesExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
1731 | 1731 | { |
1732 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1732 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1733 | 1733 | { |
1734 | 1734 | return $this; |
1735 | 1735 | } |
1736 | 1736 | $this->isObject($message, $fieldName); |
1737 | - foreach ( $keys as $key ) |
|
1737 | + foreach ($keys as $key) |
|
1738 | 1738 | { |
1739 | 1739 | // Using isset to allow resolution of magically defined properties |
1740 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1740 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1741 | 1741 | { |
1742 | 1742 | $message = $message |
1743 | 1743 | ?: sprintf( |
1744 | 1744 | 'Object does not contain a property with key "%s"', |
1745 | 1745 | $this->stringify($key) |
1746 | 1746 | ); |
1747 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, ['key' => $key]); |
|
1747 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, [ 'key' => $key ]); |
|
1748 | 1748 | } |
1749 | 1749 | } |
1750 | 1750 | |
@@ -1759,14 +1759,14 @@ discard block |
||
1759 | 1759 | * @return Assert |
1760 | 1760 | * @throws AssertionFailedException |
1761 | 1761 | */ |
1762 | - public function utf8(string $message='', string $fieldName='') : Assert |
|
1762 | + public function utf8(string $message = '', string $fieldName = '') : Assert |
|
1763 | 1763 | { |
1764 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1764 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1765 | 1765 | { |
1766 | 1766 | return $this; |
1767 | 1767 | } |
1768 | 1768 | $this->string($message, $fieldName); |
1769 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1769 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
1770 | 1770 | { |
1771 | 1771 | $message = $message |
1772 | 1772 | ?: sprintf( |
@@ -1789,14 +1789,14 @@ discard block |
||
1789 | 1789 | * @return Assert |
1790 | 1790 | * @throws AssertionFailedException |
1791 | 1791 | */ |
1792 | - public function ascii(string $message='', string $fieldName='') : Assert |
|
1792 | + public function ascii(string $message = '', string $fieldName = '') : Assert |
|
1793 | 1793 | { |
1794 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1794 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1795 | 1795 | { |
1796 | 1796 | return $this; |
1797 | 1797 | } |
1798 | 1798 | $this->string($message, $fieldName); |
1799 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1799 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
1800 | 1800 | { |
1801 | 1801 | $message = $message |
1802 | 1802 | ?: sprintf( |
@@ -1820,14 +1820,14 @@ discard block |
||
1820 | 1820 | * @return Assert |
1821 | 1821 | * @throws AssertionFailedException |
1822 | 1822 | */ |
1823 | - public function keyIsset($key, string $message='', string $fieldName='') : Assert |
|
1823 | + public function keyIsset($key, string $message = '', string $fieldName = '') : Assert |
|
1824 | 1824 | { |
1825 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1825 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1826 | 1826 | { |
1827 | 1827 | return $this; |
1828 | 1828 | } |
1829 | 1829 | $this->isArrayAccessible($message, $fieldName); |
1830 | - if ( !isset( $this->value[$key] ) ) |
|
1830 | + if ( ! isset($this->value[ $key ])) |
|
1831 | 1831 | { |
1832 | 1832 | $message = $message ?: $this->overrideError; |
1833 | 1833 | $message = sprintf( |
@@ -1835,7 +1835,7 @@ discard block |
||
1835 | 1835 | $this->stringify($key) |
1836 | 1836 | ); |
1837 | 1837 | |
1838 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, ['key' => $key]); |
|
1838 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, [ 'key' => $key ]); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | 1841 | return $this; |
@@ -1851,14 +1851,14 @@ discard block |
||
1851 | 1851 | * @return Assert |
1852 | 1852 | * @throws AssertionFailedException |
1853 | 1853 | */ |
1854 | - public function notEmptyKey($key, string $message='', string $fieldName='') : Assert |
|
1854 | + public function notEmptyKey($key, string $message = '', string $fieldName = '') : Assert |
|
1855 | 1855 | { |
1856 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1856 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1857 | 1857 | { |
1858 | 1858 | return $this; |
1859 | 1859 | } |
1860 | 1860 | $this->keyIsset($key, $message, $fieldName); |
1861 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
1861 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
1862 | 1862 | |
1863 | 1863 | return $this; |
1864 | 1864 | } |
@@ -1871,13 +1871,13 @@ discard block |
||
1871 | 1871 | * @return Assert |
1872 | 1872 | * @throws AssertionFailedException |
1873 | 1873 | */ |
1874 | - public function notBlank(string $message='', string $fieldName='') : Assert |
|
1874 | + public function notBlank(string $message = '', string $fieldName = '') : Assert |
|
1875 | 1875 | { |
1876 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1876 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1877 | 1877 | { |
1878 | 1878 | return $this; |
1879 | 1879 | } |
1880 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
1880 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
1881 | 1881 | { |
1882 | 1882 | $message = $message ?: $this->overrideError; |
1883 | 1883 | $message = sprintf( |
@@ -1900,13 +1900,13 @@ discard block |
||
1900 | 1900 | * @return Assert |
1901 | 1901 | * @throws AssertionFailedException |
1902 | 1902 | */ |
1903 | - public function isInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
1903 | + public function isInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
1904 | 1904 | { |
1905 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1905 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1906 | 1906 | { |
1907 | 1907 | return $this; |
1908 | 1908 | } |
1909 | - if ( !( $this->value instanceof $className ) ) |
|
1909 | + if ( ! ($this->value instanceof $className)) |
|
1910 | 1910 | { |
1911 | 1911 | $message = $message ?: $this->overrideError; |
1912 | 1912 | $message = sprintf( |
@@ -1915,7 +1915,7 @@ discard block |
||
1915 | 1915 | $className |
1916 | 1916 | ); |
1917 | 1917 | |
1918 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
1918 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
1919 | 1919 | } |
1920 | 1920 | |
1921 | 1921 | return $this; |
@@ -1930,13 +1930,13 @@ discard block |
||
1930 | 1930 | * @return Assert |
1931 | 1931 | * @throws AssertionFailedException |
1932 | 1932 | */ |
1933 | - public function notIsInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
1933 | + public function notIsInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
1934 | 1934 | { |
1935 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1935 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1936 | 1936 | { |
1937 | 1937 | return $this; |
1938 | 1938 | } |
1939 | - if ( $this->value instanceof $className ) |
|
1939 | + if ($this->value instanceof $className) |
|
1940 | 1940 | { |
1941 | 1941 | $message = $message ?: $this->overrideError; |
1942 | 1942 | $message = sprintf( |
@@ -1945,7 +1945,7 @@ discard block |
||
1945 | 1945 | $className |
1946 | 1946 | ); |
1947 | 1947 | |
1948 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
1948 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
1949 | 1949 | } |
1950 | 1950 | |
1951 | 1951 | return $this; |
@@ -1960,13 +1960,13 @@ discard block |
||
1960 | 1960 | * @return Assert |
1961 | 1961 | * @throws AssertionFailedException |
1962 | 1962 | */ |
1963 | - public function subclassOf(string $className, string $message='', string $fieldName='') : Assert |
|
1963 | + public function subclassOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
1964 | 1964 | { |
1965 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1965 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1966 | 1966 | { |
1967 | 1967 | return $this; |
1968 | 1968 | } |
1969 | - if ( !is_subclass_of($this->value, $className) ) |
|
1969 | + if ( ! is_subclass_of($this->value, $className)) |
|
1970 | 1970 | { |
1971 | 1971 | $message = $message ?: $this->overrideError; |
1972 | 1972 | $message = sprintf( |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | $className |
1976 | 1976 | ); |
1977 | 1977 | |
1978 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, ['class' => $className]); |
|
1978 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, [ 'class' => $className ]); |
|
1979 | 1979 | } |
1980 | 1980 | |
1981 | 1981 | return $this; |
@@ -1991,14 +1991,14 @@ discard block |
||
1991 | 1991 | * @return Assert |
1992 | 1992 | * @throws AssertionFailedException |
1993 | 1993 | */ |
1994 | - public function range(float $minValue, float $maxValue, string $message='', string $fieldName='') : Assert |
|
1994 | + public function range(float $minValue, float $maxValue, string $message = '', string $fieldName = '') : Assert |
|
1995 | 1995 | { |
1996 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1996 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1997 | 1997 | { |
1998 | 1998 | return $this; |
1999 | 1999 | } |
2000 | 2000 | $this->numeric($message, $fieldName); |
2001 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
2001 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
2002 | 2002 | { |
2003 | 2003 | $message = $message ?: $this->overrideError; |
2004 | 2004 | $message = sprintf( |
@@ -2026,14 +2026,14 @@ discard block |
||
2026 | 2026 | * @return Assert |
2027 | 2027 | * @throws AssertionFailedException |
2028 | 2028 | */ |
2029 | - public function min(int $minValue, string $message='', string $fieldName='') : Assert |
|
2029 | + public function min(int $minValue, string $message = '', string $fieldName = '') : Assert |
|
2030 | 2030 | { |
2031 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2031 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2032 | 2032 | { |
2033 | 2033 | return $this; |
2034 | 2034 | } |
2035 | 2035 | $this->numeric($message, $fieldName); |
2036 | - if ( $this->value < $minValue ) |
|
2036 | + if ($this->value < $minValue) |
|
2037 | 2037 | { |
2038 | 2038 | $message = $message ?: $this->overrideError; |
2039 | 2039 | $message = sprintf( |
@@ -2042,7 +2042,7 @@ discard block |
||
2042 | 2042 | $this->stringify($minValue) |
2043 | 2043 | ); |
2044 | 2044 | |
2045 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, ['min' => $minValue]); |
|
2045 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, [ 'min' => $minValue ]); |
|
2046 | 2046 | } |
2047 | 2047 | |
2048 | 2048 | return $this; |
@@ -2057,14 +2057,14 @@ discard block |
||
2057 | 2057 | * @return Assert |
2058 | 2058 | * @throws AssertionFailedException |
2059 | 2059 | */ |
2060 | - public function max(int $maxValue, string $message='', string $fieldName='') : Assert |
|
2060 | + public function max(int $maxValue, string $message = '', string $fieldName = '') : Assert |
|
2061 | 2061 | { |
2062 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2062 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2063 | 2063 | { |
2064 | 2064 | return $this; |
2065 | 2065 | } |
2066 | 2066 | $this->numeric($message, $fieldName); |
2067 | - if ( $this->value > $maxValue ) |
|
2067 | + if ($this->value > $maxValue) |
|
2068 | 2068 | { |
2069 | 2069 | $message = $message ?: $this->overrideError; |
2070 | 2070 | $message = sprintf( |
@@ -2073,7 +2073,7 @@ discard block |
||
2073 | 2073 | $this->stringify($maxValue) |
2074 | 2074 | ); |
2075 | 2075 | |
2076 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, ['max' => $maxValue]); |
|
2076 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, [ 'max' => $maxValue ]); |
|
2077 | 2077 | } |
2078 | 2078 | |
2079 | 2079 | return $this; |
@@ -2087,15 +2087,15 @@ discard block |
||
2087 | 2087 | * @return Assert |
2088 | 2088 | * @throws AssertionFailedException |
2089 | 2089 | */ |
2090 | - public function file(string $message='', string $fieldName='') : Assert |
|
2090 | + public function file(string $message = '', string $fieldName = '') : Assert |
|
2091 | 2091 | { |
2092 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2092 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2093 | 2093 | { |
2094 | 2094 | return $this; |
2095 | 2095 | } |
2096 | 2096 | $this->string($message, $fieldName); |
2097 | 2097 | $this->notEmpty($message, $fieldName); |
2098 | - if ( !is_file($this->value) ) |
|
2098 | + if ( ! is_file($this->value)) |
|
2099 | 2099 | { |
2100 | 2100 | $message = $message ?: $this->overrideError; |
2101 | 2101 | $message = sprintf( |
@@ -2117,15 +2117,15 @@ discard block |
||
2117 | 2117 | * @return Assert |
2118 | 2118 | * @throws AssertionFailedException |
2119 | 2119 | */ |
2120 | - public function fileOrDirectoryExists(string $message='', string $fieldName='') : Assert |
|
2120 | + public function fileOrDirectoryExists(string $message = '', string $fieldName = '') : Assert |
|
2121 | 2121 | { |
2122 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2122 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2123 | 2123 | { |
2124 | 2124 | return $this; |
2125 | 2125 | } |
2126 | 2126 | $this->string($message, $fieldName); |
2127 | 2127 | $this->notEmpty($message, $fieldName); |
2128 | - if ( ! file_exists($this->value) ) |
|
2128 | + if ( ! file_exists($this->value)) |
|
2129 | 2129 | { |
2130 | 2130 | $message = $message ?: $this->overrideError; |
2131 | 2131 | $message = sprintf( |
@@ -2147,14 +2147,14 @@ discard block |
||
2147 | 2147 | * @return Assert |
2148 | 2148 | * @throws AssertionFailedException |
2149 | 2149 | */ |
2150 | - public function directory(string $message='', string $fieldName='') : Assert |
|
2150 | + public function directory(string $message = '', string $fieldName = '') : Assert |
|
2151 | 2151 | { |
2152 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2152 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2153 | 2153 | { |
2154 | 2154 | return $this; |
2155 | 2155 | } |
2156 | 2156 | $this->string($message, $fieldName); |
2157 | - if ( !is_dir($this->value) ) |
|
2157 | + if ( ! is_dir($this->value)) |
|
2158 | 2158 | { |
2159 | 2159 | $message = $message ?: $this->overrideError; |
2160 | 2160 | $message = sprintf( |
@@ -2176,14 +2176,14 @@ discard block |
||
2176 | 2176 | * @return Assert |
2177 | 2177 | * @throws AssertionFailedException |
2178 | 2178 | */ |
2179 | - public function readable(string $message='', string $fieldName='') : Assert |
|
2179 | + public function readable(string $message = '', string $fieldName = '') : Assert |
|
2180 | 2180 | { |
2181 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2181 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2182 | 2182 | { |
2183 | 2183 | return $this; |
2184 | 2184 | } |
2185 | 2185 | $this->string($message, $fieldName); |
2186 | - if ( !is_readable($this->value) ) |
|
2186 | + if ( ! is_readable($this->value)) |
|
2187 | 2187 | { |
2188 | 2188 | $message = $message ?: $this->overrideError; |
2189 | 2189 | $message = sprintf( |
@@ -2205,14 +2205,14 @@ discard block |
||
2205 | 2205 | * @return Assert |
2206 | 2206 | * @throws AssertionFailedException |
2207 | 2207 | */ |
2208 | - public function writeable(string $message='', string $fieldName='') : Assert |
|
2208 | + public function writeable(string $message = '', string $fieldName = '') : Assert |
|
2209 | 2209 | { |
2210 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2210 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2211 | 2211 | { |
2212 | 2212 | return $this; |
2213 | 2213 | } |
2214 | 2214 | $this->string($message, $fieldName); |
2215 | - if ( !is_writeable($this->value) ) |
|
2215 | + if ( ! is_writeable($this->value)) |
|
2216 | 2216 | { |
2217 | 2217 | $message = $message ?: $this->overrideError; |
2218 | 2218 | $message = sprintf( |
@@ -2234,14 +2234,14 @@ discard block |
||
2234 | 2234 | * @return Assert |
2235 | 2235 | * @throws AssertionFailedException |
2236 | 2236 | */ |
2237 | - public function email(string $message='', string $fieldName='') : Assert |
|
2237 | + public function email(string $message = '', string $fieldName = '') : Assert |
|
2238 | 2238 | { |
2239 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2239 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2240 | 2240 | { |
2241 | 2241 | return $this; |
2242 | 2242 | } |
2243 | 2243 | $this->string($message, $fieldName); |
2244 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
2244 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
2245 | 2245 | { |
2246 | 2246 | $message = $message ?: $this->overrideError; |
2247 | 2247 | $message = sprintf( |
@@ -2255,7 +2255,7 @@ discard block |
||
2255 | 2255 | { |
2256 | 2256 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2257 | 2257 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
2258 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
2258 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
2259 | 2259 | { |
2260 | 2260 | $message = $message ?: $this->overrideError; |
2261 | 2261 | $message = sprintf( |
@@ -2277,9 +2277,9 @@ discard block |
||
2277 | 2277 | * @return Assert |
2278 | 2278 | * @throws AssertionFailedException |
2279 | 2279 | */ |
2280 | - public function emailPrefix(string $message='', string $fieldName='') : Assert |
|
2280 | + public function emailPrefix(string $message = '', string $fieldName = '') : Assert |
|
2281 | 2281 | { |
2282 | - $this->value($this->value . '@example.com'); |
|
2282 | + $this->value($this->value.'@example.com'); |
|
2283 | 2283 | |
2284 | 2284 | return $this->email($message, $fieldName); |
2285 | 2285 | } |
@@ -2298,14 +2298,14 @@ discard block |
||
2298 | 2298 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
2299 | 2299 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
2300 | 2300 | */ |
2301 | - public function url(string $message='', string $fieldName='') : Assert |
|
2301 | + public function url(string $message = '', string $fieldName = '') : Assert |
|
2302 | 2302 | { |
2303 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2303 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2304 | 2304 | { |
2305 | 2305 | return $this; |
2306 | 2306 | } |
2307 | 2307 | $this->string($message, $fieldName); |
2308 | - $protocols = ['http', 'https']; |
|
2308 | + $protocols = [ 'http', 'https' ]; |
|
2309 | 2309 | $pattern = '~^ |
2310 | 2310 | (%s):// # protocol |
2311 | 2311 | ( |
@@ -2320,8 +2320,8 @@ discard block |
||
2320 | 2320 | (:[0-9]+)? # a port (optional) |
2321 | 2321 | (/?|/\S+) # a /, nothing or a / with something |
2322 | 2322 | $~ixu'; |
2323 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2324 | - if ( !preg_match($pattern, $this->value) ) |
|
2323 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2324 | + if ( ! preg_match($pattern, $this->value)) |
|
2325 | 2325 | { |
2326 | 2326 | $message = $message ?: $this->overrideError; |
2327 | 2327 | $message = sprintf( |
@@ -2346,15 +2346,15 @@ discard block |
||
2346 | 2346 | * @throws AssertionFailedException |
2347 | 2347 | * |
2348 | 2348 | */ |
2349 | - public function domainName(string $message='', string $fieldName='') : Assert |
|
2349 | + public function domainName(string $message = '', string $fieldName = '') : Assert |
|
2350 | 2350 | { |
2351 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2351 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2352 | 2352 | { |
2353 | 2353 | return $this; |
2354 | 2354 | } |
2355 | 2355 | $this->string($message, $fieldName); |
2356 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2357 | - if ( ! preg_match($pattern, $this->value) ) |
|
2356 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2357 | + if ( ! preg_match($pattern, $this->value)) |
|
2358 | 2358 | { |
2359 | 2359 | $message = $message ?: $this->overrideError; |
2360 | 2360 | $message = sprintf( |
@@ -2376,14 +2376,14 @@ discard block |
||
2376 | 2376 | * @return $this |
2377 | 2377 | * @throws AssertionFailedException |
2378 | 2378 | */ |
2379 | - public function ausMobile(string $message='', string $fieldName='') : Assert |
|
2379 | + public function ausMobile(string $message = '', string $fieldName = '') : Assert |
|
2380 | 2380 | { |
2381 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2381 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2382 | 2382 | { |
2383 | 2383 | return $this; |
2384 | 2384 | } |
2385 | 2385 | $this->string($message, $fieldName); |
2386 | - if ( ! static::isAusMobile($this->value) ) |
|
2386 | + if ( ! static::isAusMobile($this->value)) |
|
2387 | 2387 | { |
2388 | 2388 | $message = $message ?: $this->overrideError; |
2389 | 2389 | $message = sprintf( |
@@ -2415,9 +2415,9 @@ discard block |
||
2415 | 2415 | * @return Assert |
2416 | 2416 | * @throws AssertionFailedException |
2417 | 2417 | */ |
2418 | - public function alnum(string $message='', string $fieldName='') : Assert |
|
2418 | + public function alnum(string $message = '', string $fieldName = '') : Assert |
|
2419 | 2419 | { |
2420 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2420 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2421 | 2421 | { |
2422 | 2422 | return $this; |
2423 | 2423 | } |
@@ -2448,13 +2448,13 @@ discard block |
||
2448 | 2448 | * @return Assert |
2449 | 2449 | * @throws AssertionFailedException |
2450 | 2450 | */ |
2451 | - public function true(string $message='', string $fieldName='') : Assert |
|
2451 | + public function true(string $message = '', string $fieldName = '') : Assert |
|
2452 | 2452 | { |
2453 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2453 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2454 | 2454 | { |
2455 | 2455 | return $this; |
2456 | 2456 | } |
2457 | - if ( $this->value !== true ) |
|
2457 | + if ($this->value !== true) |
|
2458 | 2458 | { |
2459 | 2459 | $message = $message ?: $this->overrideError; |
2460 | 2460 | $message = sprintf( |
@@ -2476,13 +2476,13 @@ discard block |
||
2476 | 2476 | * @return Assert |
2477 | 2477 | * @throws AssertionFailedException |
2478 | 2478 | */ |
2479 | - public function truthy(string $message='', string $fieldName='') : Assert |
|
2479 | + public function truthy(string $message = '', string $fieldName = '') : Assert |
|
2480 | 2480 | { |
2481 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2481 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2482 | 2482 | { |
2483 | 2483 | return $this; |
2484 | 2484 | } |
2485 | - if ( ! $this->value ) |
|
2485 | + if ( ! $this->value) |
|
2486 | 2486 | { |
2487 | 2487 | $message = $message ?: $this->overrideError; |
2488 | 2488 | $message = sprintf( |
@@ -2504,13 +2504,13 @@ discard block |
||
2504 | 2504 | * @return Assert |
2505 | 2505 | * @throws AssertionFailedException |
2506 | 2506 | */ |
2507 | - public function false(string $message='', string $fieldName='') : Assert |
|
2507 | + public function false(string $message = '', string $fieldName = '') : Assert |
|
2508 | 2508 | { |
2509 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2509 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2510 | 2510 | { |
2511 | 2511 | return $this; |
2512 | 2512 | } |
2513 | - if ( $this->value !== false ) |
|
2513 | + if ($this->value !== false) |
|
2514 | 2514 | { |
2515 | 2515 | $message = $message ?: $this->overrideError; |
2516 | 2516 | $message = sprintf( |
@@ -2532,13 +2532,13 @@ discard block |
||
2532 | 2532 | * @return Assert |
2533 | 2533 | * @throws AssertionFailedException |
2534 | 2534 | */ |
2535 | - public function notFalse(string $message='', string $fieldName='') : Assert |
|
2535 | + public function notFalse(string $message = '', string $fieldName = '') : Assert |
|
2536 | 2536 | { |
2537 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2537 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2538 | 2538 | { |
2539 | 2539 | return $this; |
2540 | 2540 | } |
2541 | - if ( $this->value === false ) |
|
2541 | + if ($this->value === false) |
|
2542 | 2542 | { |
2543 | 2543 | $message = $message ?: $this->overrideError; |
2544 | 2544 | $message = sprintf( |
@@ -2560,13 +2560,13 @@ discard block |
||
2560 | 2560 | * @return Assert |
2561 | 2561 | * @throws AssertionFailedException |
2562 | 2562 | */ |
2563 | - public function classExists(string $message='', string $fieldName='') : Assert |
|
2563 | + public function classExists(string $message = '', string $fieldName = '') : Assert |
|
2564 | 2564 | { |
2565 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2565 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2566 | 2566 | { |
2567 | 2567 | return $this; |
2568 | 2568 | } |
2569 | - if ( !class_exists($this->value) ) |
|
2569 | + if ( ! class_exists($this->value)) |
|
2570 | 2570 | { |
2571 | 2571 | $message = $message ?: $this->overrideError; |
2572 | 2572 | $message = sprintf( |
@@ -2588,14 +2588,14 @@ discard block |
||
2588 | 2588 | * @throws AssertionFailedException |
2589 | 2589 | * @throws \ReflectionException |
2590 | 2590 | */ |
2591 | - public function implementsInterface(string $interfaceName, string $message='', string $fieldName='') : Assert |
|
2591 | + public function implementsInterface(string $interfaceName, string $message = '', string $fieldName = '') : Assert |
|
2592 | 2592 | { |
2593 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2593 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2594 | 2594 | { |
2595 | 2595 | return $this; |
2596 | 2596 | } |
2597 | 2597 | $reflection = new \ReflectionClass($this->value); |
2598 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
2598 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
2599 | 2599 | { |
2600 | 2600 | $message = $message ?: $this->overrideError; |
2601 | 2601 | $message = sprintf( |
@@ -2604,7 +2604,7 @@ discard block |
||
2604 | 2604 | $this->stringify($interfaceName) |
2605 | 2605 | ); |
2606 | 2606 | |
2607 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, ['interface' => $interfaceName]); |
|
2607 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, [ 'interface' => $interfaceName ]); |
|
2608 | 2608 | } |
2609 | 2609 | |
2610 | 2610 | return $this; |
@@ -2624,13 +2624,13 @@ discard block |
||
2624 | 2624 | * @return Assert |
2625 | 2625 | * @throws AssertionFailedException |
2626 | 2626 | */ |
2627 | - public function isJsonString(string $message='', string $fieldName='') : Assert |
|
2627 | + public function isJsonString(string $message = '', string $fieldName = '') : Assert |
|
2628 | 2628 | { |
2629 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2629 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2630 | 2630 | { |
2631 | 2631 | return $this; |
2632 | 2632 | } |
2633 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
2633 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
2634 | 2634 | { |
2635 | 2635 | $message = $message ?: $this->overrideError; |
2636 | 2636 | $message = sprintf( |
@@ -2654,18 +2654,18 @@ discard block |
||
2654 | 2654 | * @return Assert |
2655 | 2655 | * @throws AssertionFailedException |
2656 | 2656 | */ |
2657 | - public function uuid(string $message='', string $fieldName='') : Assert |
|
2657 | + public function uuid(string $message = '', string $fieldName = '') : Assert |
|
2658 | 2658 | { |
2659 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2659 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2660 | 2660 | { |
2661 | 2661 | return $this; |
2662 | 2662 | } |
2663 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
2664 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
2663 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
2664 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
2665 | 2665 | { |
2666 | 2666 | return $this; |
2667 | 2667 | } |
2668 | - if ( !preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $this->value) ) |
|
2668 | + if ( ! preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $this->value)) |
|
2669 | 2669 | { |
2670 | 2670 | $message = $message ?: $this->overrideError; |
2671 | 2671 | $message = sprintf( |
@@ -2694,13 +2694,13 @@ discard block |
||
2694 | 2694 | * @return Assert |
2695 | 2695 | * @throws AssertionFailedException |
2696 | 2696 | */ |
2697 | - public function samAccountName(string $message='', string $fieldName='') : Assert |
|
2697 | + public function samAccountName(string $message = '', string $fieldName = '') : Assert |
|
2698 | 2698 | { |
2699 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2699 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2700 | 2700 | { |
2701 | 2701 | return $this; |
2702 | 2702 | } |
2703 | - if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
2703 | + if ( ! preg_match('/^([a-z0-9]{4,20})$/', $this->value)) |
|
2704 | 2704 | { |
2705 | 2705 | $message = $message ?: $this->overrideError; |
2706 | 2706 | $message = sprintf( |
@@ -2722,9 +2722,9 @@ discard block |
||
2722 | 2722 | * @return Assert |
2723 | 2723 | * @throws AssertionFailedException |
2724 | 2724 | */ |
2725 | - public function userPrincipalName(string $message='', string $fieldName='') : Assert |
|
2725 | + public function userPrincipalName(string $message = '', string $fieldName = '') : Assert |
|
2726 | 2726 | { |
2727 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2727 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2728 | 2728 | { |
2729 | 2729 | return $this; |
2730 | 2730 | } |
@@ -2757,13 +2757,13 @@ discard block |
||
2757 | 2757 | * @return Assert |
2758 | 2758 | * @throws AssertionFailedException |
2759 | 2759 | */ |
2760 | - public function isni(string $message='', string $fieldName='') |
|
2760 | + public function isni(string $message = '', string $fieldName = '') |
|
2761 | 2761 | { |
2762 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2762 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2763 | 2763 | { |
2764 | 2764 | return $this; |
2765 | 2765 | } |
2766 | - if ( !preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value) ) |
|
2766 | + if ( ! preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value)) |
|
2767 | 2767 | { |
2768 | 2768 | $message = $message ?: $this->overrideError; |
2769 | 2769 | $message = sprintf( |
@@ -2786,13 +2786,13 @@ discard block |
||
2786 | 2786 | * @return Assert |
2787 | 2787 | * @throws AssertionFailedException |
2788 | 2788 | */ |
2789 | - public function count(int $count, string $message='', string $fieldName='') : Assert |
|
2789 | + public function count(int $count, string $message = '', string $fieldName = '') : Assert |
|
2790 | 2790 | { |
2791 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2791 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2792 | 2792 | { |
2793 | 2793 | return $this; |
2794 | 2794 | } |
2795 | - if ( $count !== count($this->value) ) |
|
2795 | + if ($count !== count($this->value)) |
|
2796 | 2796 | { |
2797 | 2797 | $message = $message ?: $this->overrideError; |
2798 | 2798 | $message = sprintf( |
@@ -2801,7 +2801,7 @@ discard block |
||
2801 | 2801 | $this->stringify($count) |
2802 | 2802 | ); |
2803 | 2803 | |
2804 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, ['count' => $count]); |
|
2804 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, [ 'count' => $count ]); |
|
2805 | 2805 | } |
2806 | 2806 | |
2807 | 2807 | return $this; |
@@ -2815,25 +2815,25 @@ discard block |
||
2815 | 2815 | */ |
2816 | 2816 | protected function doAllOrNullOr($func, $args) : bool |
2817 | 2817 | { |
2818 | - if ( $this->nullOr && is_null($this->value) ) |
|
2818 | + if ($this->nullOr && is_null($this->value)) |
|
2819 | 2819 | { |
2820 | 2820 | return true; |
2821 | 2821 | } |
2822 | - if ( $this->emptyOr && empty($this->value) ) |
|
2822 | + if ($this->emptyOr && empty($this->value)) |
|
2823 | 2823 | { |
2824 | 2824 | return true; |
2825 | 2825 | } |
2826 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
2826 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
2827 | 2827 | { |
2828 | - foreach ( $this->value as $idx => $value ) |
|
2828 | + foreach ($this->value as $idx => $value) |
|
2829 | 2829 | { |
2830 | 2830 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
2831 | - call_user_func_array([$object, $func], $args); |
|
2831 | + call_user_func_array([ $object, $func ], $args); |
|
2832 | 2832 | } |
2833 | 2833 | return true; |
2834 | 2834 | } |
2835 | 2835 | |
2836 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
2836 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
2837 | 2837 | } |
2838 | 2838 | |
2839 | 2839 | /** |
@@ -2845,14 +2845,14 @@ discard block |
||
2845 | 2845 | * @return Assert |
2846 | 2846 | * @throws AssertionFailedException |
2847 | 2847 | */ |
2848 | - public function choicesNotEmpty(array $choices, string $message='', string $fieldName='') : Assert |
|
2848 | + public function choicesNotEmpty(array $choices, string $message = '', string $fieldName = '') : Assert |
|
2849 | 2849 | { |
2850 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2850 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2851 | 2851 | { |
2852 | 2852 | return $this; |
2853 | 2853 | } |
2854 | 2854 | $this->notEmpty($message, $fieldName); |
2855 | - foreach ( $choices as $choice ) |
|
2855 | + foreach ($choices as $choice) |
|
2856 | 2856 | { |
2857 | 2857 | $this->notEmptyKey($choice, $message, $fieldName); |
2858 | 2858 | } |
@@ -2869,14 +2869,14 @@ discard block |
||
2869 | 2869 | * @return Assert |
2870 | 2870 | * @throws AssertionFailedException |
2871 | 2871 | */ |
2872 | - public function methodExists($object, string $message='', string $fieldName='') : Assert |
|
2872 | + public function methodExists($object, string $message = '', string $fieldName = '') : Assert |
|
2873 | 2873 | { |
2874 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2874 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2875 | 2875 | { |
2876 | 2876 | return $this; |
2877 | 2877 | } |
2878 | 2878 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $fieldName); |
2879 | - if ( !method_exists($object, $this->value) ) |
|
2879 | + if ( ! method_exists($object, $this->value)) |
|
2880 | 2880 | { |
2881 | 2881 | $message = $message ?: $this->overrideError; |
2882 | 2882 | $message = sprintf( |
@@ -2898,13 +2898,13 @@ discard block |
||
2898 | 2898 | * @return Assert |
2899 | 2899 | * @throws AssertionFailedException |
2900 | 2900 | */ |
2901 | - public function isObject(string $message='', string $fieldName='') : Assert |
|
2901 | + public function isObject(string $message = '', string $fieldName = '') : Assert |
|
2902 | 2902 | { |
2903 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2903 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2904 | 2904 | { |
2905 | 2905 | return $this; |
2906 | 2906 | } |
2907 | - if ( !is_object($this->value) ) |
|
2907 | + if ( ! is_object($this->value)) |
|
2908 | 2908 | { |
2909 | 2909 | $message = $message ?: $this->overrideError; |
2910 | 2910 | $message = sprintf( |
@@ -2926,33 +2926,33 @@ discard block |
||
2926 | 2926 | */ |
2927 | 2927 | private function stringify($value) : string |
2928 | 2928 | { |
2929 | - if ( is_bool($value) ) |
|
2929 | + if (is_bool($value)) |
|
2930 | 2930 | { |
2931 | 2931 | return $value ? '<TRUE>' : '<FALSE>'; |
2932 | 2932 | } |
2933 | - if ( is_scalar($value) ) |
|
2933 | + if (is_scalar($value)) |
|
2934 | 2934 | { |
2935 | 2935 | $val = (string)$value; |
2936 | - if ( strlen($val) > 100 ) |
|
2936 | + if (strlen($val) > 100) |
|
2937 | 2937 | { |
2938 | - $val = substr($val, 0, 97) . '...'; |
|
2938 | + $val = substr($val, 0, 97).'...'; |
|
2939 | 2939 | } |
2940 | 2940 | |
2941 | 2941 | return $val; |
2942 | 2942 | } |
2943 | - if ( is_array($value) ) |
|
2943 | + if (is_array($value)) |
|
2944 | 2944 | { |
2945 | 2945 | return '<ARRAY>'; |
2946 | 2946 | } |
2947 | - if ( is_object($value) ) |
|
2947 | + if (is_object($value)) |
|
2948 | 2948 | { |
2949 | 2949 | return get_class($value); |
2950 | 2950 | } |
2951 | - if ( is_resource($value) ) |
|
2951 | + if (is_resource($value)) |
|
2952 | 2952 | { |
2953 | 2953 | return '<RESOURCE>'; |
2954 | 2954 | } |
2955 | - if ( $value === null ) |
|
2955 | + if ($value === null) |
|
2956 | 2956 | { |
2957 | 2957 | return '<NULL>'; |
2958 | 2958 | } |
@@ -158,8 +158,7 @@ discard block |
||
158 | 158 | try |
159 | 159 | { |
160 | 160 | $validator->__invoke(); |
161 | - } |
|
162 | - catch ( AssertionFailedException $e ) |
|
161 | + } catch ( AssertionFailedException $e ) |
|
163 | 162 | { |
164 | 163 | $errors[$fieldName] = $e->getMessage(); |
165 | 164 | } |
@@ -2250,8 +2249,7 @@ discard block |
||
2250 | 2249 | ); |
2251 | 2250 | |
2252 | 2251 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_EMAIL, $fieldName); |
2253 | - } |
|
2254 | - else |
|
2252 | + } else |
|
2255 | 2253 | { |
2256 | 2254 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2257 | 2255 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
@@ -2424,8 +2422,7 @@ discard block |
||
2424 | 2422 | try |
2425 | 2423 | { |
2426 | 2424 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName); |
2427 | - } |
|
2428 | - catch (AssertionFailedException $e) |
|
2425 | + } catch (AssertionFailedException $e) |
|
2429 | 2426 | { |
2430 | 2427 | $message = $message ?: $this->overrideError; |
2431 | 2428 | $message = sprintf( |
@@ -2731,8 +2728,7 @@ discard block |
||
2731 | 2728 | try |
2732 | 2729 | { |
2733 | 2730 | $this->email($message, $fieldName); |
2734 | - } |
|
2735 | - catch (AssertionFailedException $e) |
|
2731 | + } catch (AssertionFailedException $e) |
|
2736 | 2732 | { |
2737 | 2733 | $message = $message ?: $this->overrideError; |
2738 | 2734 | $message = sprintf( |