@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | /** |
1409 | 1409 | * Alias of {@see choice()} |
1410 | 1410 | * |
1411 | - * @param array $choices |
|
1411 | + * @param integer[] $choices |
|
1412 | 1412 | * @param string $message |
1413 | 1413 | * @param string $fieldName |
1414 | 1414 | * @return Assert |
@@ -1585,7 +1585,7 @@ discard block |
||
1585 | 1585 | /** |
1586 | 1586 | * Assert that key exists in the values array. |
1587 | 1587 | * |
1588 | - * @param string|integer $key |
|
1588 | + * @param string $key |
|
1589 | 1589 | * @param string $message |
1590 | 1590 | * @param string $fieldName |
1591 | 1591 | * @return Assert |
@@ -2728,7 +2728,7 @@ discard block |
||
2728 | 2728 | } |
2729 | 2729 | |
2730 | 2730 | /** |
2731 | - * @param $func |
|
2731 | + * @param string $func |
|
2732 | 2732 | * @param $args |
2733 | 2733 | * @return bool |
2734 | 2734 | * @throws AssertionFailedException |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @var string |
136 | 136 | */ |
137 | - protected $exceptionClass = AssertionFailedException::class; |
|
137 | + protected $exceptionClass = AssertionFailedException::class; |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @param mixed $value |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public static function runValidators(array $validators) : array |
153 | 153 | { |
154 | - $errors = []; |
|
155 | - foreach ( $validators as $fieldName => $validator ) |
|
154 | + $errors = [ ]; |
|
155 | + foreach ($validators as $fieldName => $validator) |
|
156 | 156 | { |
157 | 157 | try |
158 | 158 | { |
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; |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function eq($value2, string $message = '', string $fieldName = '') : Assert |
364 | 364 | { |
365 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
365 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
366 | 366 | { |
367 | 367 | return $this; |
368 | 368 | } |
369 | - if ( $this->value != $value2 ) |
|
369 | + if ($this->value != $value2) |
|
370 | 370 | { |
371 | 371 | $message = $message ?: $this->overrideError; |
372 | 372 | $message = sprintf( |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $this->stringify($value2) |
376 | 376 | ); |
377 | 377 | |
378 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
378 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | return $this; |
@@ -392,11 +392,11 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function greaterThan($value2, string $message = '', string $fieldName = '') : Assert |
394 | 394 | { |
395 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
395 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
396 | 396 | { |
397 | 397 | return $this; |
398 | 398 | } |
399 | - if ( ! ( $this->value > $value2 ) ) |
|
399 | + if ( ! ($this->value > $value2)) |
|
400 | 400 | { |
401 | 401 | $message = $message ?: $this->overrideError; |
402 | 402 | $message = sprintf( |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $this->stringify($value2) |
406 | 406 | ); |
407 | 407 | |
408 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
408 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return $this; |
@@ -422,11 +422,11 @@ discard block |
||
422 | 422 | */ |
423 | 423 | public function greaterThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
424 | 424 | { |
425 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
425 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
426 | 426 | { |
427 | 427 | return $this; |
428 | 428 | } |
429 | - if ( ! ( $this->value >= $value2 ) ) |
|
429 | + if ( ! ($this->value >= $value2)) |
|
430 | 430 | { |
431 | 431 | $message = $message ?: $this->overrideError; |
432 | 432 | $message = sprintf( |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $this->stringify($value2) |
436 | 436 | ); |
437 | 437 | |
438 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
438 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | return $this; |
@@ -452,11 +452,11 @@ discard block |
||
452 | 452 | */ |
453 | 453 | public function lessThan($value2, string $message = '', string $fieldName = '') : Assert |
454 | 454 | { |
455 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
455 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
456 | 456 | { |
457 | 457 | return $this; |
458 | 458 | } |
459 | - if ( ! ( $this->value < $value2 ) ) |
|
459 | + if ( ! ($this->value < $value2)) |
|
460 | 460 | { |
461 | 461 | $message = $message ?: $this->overrideError; |
462 | 462 | $message = sprintf( |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | $this->stringify($value2) |
466 | 466 | ); |
467 | 467 | |
468 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, ['expected' => $value2]); |
|
468 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, [ 'expected' => $value2 ]); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | return $this; |
@@ -482,11 +482,11 @@ discard block |
||
482 | 482 | */ |
483 | 483 | public function lessThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
484 | 484 | { |
485 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
485 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
486 | 486 | { |
487 | 487 | return $this; |
488 | 488 | } |
489 | - if ( ! ( $this->value <= $value2 ) ) |
|
489 | + if ( ! ($this->value <= $value2)) |
|
490 | 490 | { |
491 | 491 | $message = $message ?: $this->overrideError; |
492 | 492 | $message = sprintf( |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $this->stringify($value2) |
496 | 496 | ); |
497 | 497 | |
498 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, ['expected' => $value2]); |
|
498 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | return $this; |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | */ |
513 | 513 | public function same($value2, string $message = '', string $fieldName = '') : Assert |
514 | 514 | { |
515 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
515 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
516 | 516 | { |
517 | 517 | return $this; |
518 | 518 | } |
519 | - if ( $this->value !== $value2 ) |
|
519 | + if ($this->value !== $value2) |
|
520 | 520 | { |
521 | 521 | $message = $message ?: $this->overrideError; |
522 | 522 | $message = sprintf( |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | $this->stringify($value2) |
526 | 526 | ); |
527 | 527 | |
528 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, ['expected' => $value2]); |
|
528 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | return $this; |
@@ -542,11 +542,11 @@ discard block |
||
542 | 542 | */ |
543 | 543 | public function notEq($value2, string $message = '', string $fieldName = '') : Assert |
544 | 544 | { |
545 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
545 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
546 | 546 | { |
547 | 547 | return $this; |
548 | 548 | } |
549 | - if ( $this->value == $value2 ) |
|
549 | + if ($this->value == $value2) |
|
550 | 550 | { |
551 | 551 | $message = $message ?: $this->overrideError; |
552 | 552 | $message = sprintf( |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | $this->stringify($value2) |
556 | 556 | ); |
557 | 557 | |
558 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, ['expected' => $value2]); |
|
558 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | return $this; |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | */ |
572 | 572 | public function isCallable(string $message = '', string $fieldName = '') : Assert |
573 | 573 | { |
574 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
574 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
575 | 575 | { |
576 | 576 | return $this; |
577 | 577 | } |
578 | - if ( !is_callable($this->value) ) |
|
578 | + if ( ! is_callable($this->value)) |
|
579 | 579 | { |
580 | 580 | $message = $message ?: $this->overrideError; |
581 | 581 | $message = sprintf( |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | */ |
601 | 601 | public function notSame($value2, string $message = '', string $fieldName = '') : Assert |
602 | 602 | { |
603 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
603 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
604 | 604 | { |
605 | 605 | return $this; |
606 | 606 | } |
607 | - if ( $this->value === $value2 ) |
|
607 | + if ($this->value === $value2) |
|
608 | 608 | { |
609 | 609 | $message = $message ?: $this->overrideError; |
610 | 610 | $message = sprintf( |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | $this->stringify($value2) |
614 | 614 | ); |
615 | 615 | |
616 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, ['expected' => $value2]); |
|
616 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | return $this; |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | $message = $message ?: $this->overrideError; |
680 | 680 | $message = $message ?: 'Value "%s" is not a valid status.'; |
681 | 681 | |
682 | - return $this->integer($message, $fieldName)->inArray([-1, 0, 1]); |
|
682 | + return $this->integer($message, $fieldName)->inArray([-1, 0, 1 ]); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | /** |
@@ -731,11 +731,11 @@ discard block |
||
731 | 731 | */ |
732 | 732 | public function integer(string $message = '', string $fieldName = '') : Assert |
733 | 733 | { |
734 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
734 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
735 | 735 | { |
736 | 736 | return $this; |
737 | 737 | } |
738 | - if ( !is_int($this->value) ) |
|
738 | + if ( ! is_int($this->value)) |
|
739 | 739 | { |
740 | 740 | $message = $message ?: $this->overrideError; |
741 | 741 | $message = sprintf( |
@@ -759,11 +759,11 @@ discard block |
||
759 | 759 | */ |
760 | 760 | public function float(string $message = '', string $fieldName = '') : Assert |
761 | 761 | { |
762 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
762 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
763 | 763 | { |
764 | 764 | return $this; |
765 | 765 | } |
766 | - if ( ! is_float($this->value) ) |
|
766 | + if ( ! is_float($this->value)) |
|
767 | 767 | { |
768 | 768 | $message = $message ?: $this->overrideError; |
769 | 769 | $message = sprintf( |
@@ -787,11 +787,11 @@ discard block |
||
787 | 787 | */ |
788 | 788 | public function digit(string $message = '', string $fieldName = '') : Assert |
789 | 789 | { |
790 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
790 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
791 | 791 | { |
792 | 792 | return $this; |
793 | 793 | } |
794 | - if ( ! ctype_digit((string)$this->value) ) |
|
794 | + if ( ! ctype_digit((string)$this->value)) |
|
795 | 795 | { |
796 | 796 | $message = $message ?: $this->overrideError; |
797 | 797 | $message = sprintf( |
@@ -815,12 +815,12 @@ discard block |
||
815 | 815 | */ |
816 | 816 | public function date(string $message = '', string $fieldName = '') : Assert |
817 | 817 | { |
818 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
818 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
819 | 819 | { |
820 | 820 | return $this; |
821 | 821 | } |
822 | 822 | $this->notEmpty($message, $fieldName); |
823 | - if ( strtotime($this->value) === false ) |
|
823 | + if (strtotime($this->value) === false) |
|
824 | 824 | { |
825 | 825 | $message = $message ?: $this->overrideError; |
826 | 826 | $message = sprintf( |
@@ -844,11 +844,11 @@ discard block |
||
844 | 844 | */ |
845 | 845 | public function integerish(string $message = '', string $fieldName = '') : Assert |
846 | 846 | { |
847 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
847 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
848 | 848 | { |
849 | 849 | return $this; |
850 | 850 | } |
851 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
851 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
852 | 852 | { |
853 | 853 | $message = $message ?: $this->overrideError; |
854 | 854 | $message = sprintf( |
@@ -872,11 +872,11 @@ discard block |
||
872 | 872 | */ |
873 | 873 | public function boolean(string $message = '', string $fieldName = '') : Assert |
874 | 874 | { |
875 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
875 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
876 | 876 | { |
877 | 877 | return $this; |
878 | 878 | } |
879 | - if ( ! is_bool($this->value) ) |
|
879 | + if ( ! is_bool($this->value)) |
|
880 | 880 | { |
881 | 881 | $message = $message ?: $this->overrideError; |
882 | 882 | $message = sprintf( |
@@ -900,11 +900,11 @@ discard block |
||
900 | 900 | */ |
901 | 901 | public function scalar(string $message = '', string $fieldName = '') : Assert |
902 | 902 | { |
903 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
903 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
904 | 904 | { |
905 | 905 | return $this; |
906 | 906 | } |
907 | - if ( ! is_scalar($this->value) ) |
|
907 | + if ( ! is_scalar($this->value)) |
|
908 | 908 | { |
909 | 909 | $message = $message ?: $this->overrideError; |
910 | 910 | $message = sprintf( |
@@ -928,11 +928,11 @@ discard block |
||
928 | 928 | */ |
929 | 929 | public function notEmpty(string $message = '', string $fieldName = '') : Assert |
930 | 930 | { |
931 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
931 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
932 | 932 | { |
933 | 933 | return $this; |
934 | 934 | } |
935 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
935 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
936 | 936 | { |
937 | 937 | $message = $message ?: $this->overrideError; |
938 | 938 | $message = sprintf( |
@@ -956,11 +956,11 @@ discard block |
||
956 | 956 | */ |
957 | 957 | public function noContent(string $message = '', string $fieldName = '') : Assert |
958 | 958 | { |
959 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
959 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
960 | 960 | { |
961 | 961 | return $this; |
962 | 962 | } |
963 | - if ( !empty( $this->value ) ) |
|
963 | + if ( ! empty($this->value)) |
|
964 | 964 | { |
965 | 965 | $message = $message ?: $this->overrideError; |
966 | 966 | $message = sprintf( |
@@ -984,11 +984,11 @@ discard block |
||
984 | 984 | */ |
985 | 985 | public function notNull(string $message = '', string $fieldName = '') : Assert |
986 | 986 | { |
987 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
987 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
988 | 988 | { |
989 | 989 | return $this; |
990 | 990 | } |
991 | - if ( $this->value === null ) |
|
991 | + if ($this->value === null) |
|
992 | 992 | { |
993 | 993 | $message = $message ?: $this->overrideError; |
994 | 994 | $message = sprintf( |
@@ -1012,11 +1012,11 @@ discard block |
||
1012 | 1012 | */ |
1013 | 1013 | public function string(string $message = '', string $fieldName = '') : Assert |
1014 | 1014 | { |
1015 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1015 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1016 | 1016 | { |
1017 | 1017 | return $this; |
1018 | 1018 | } |
1019 | - if ( !is_string($this->value) ) |
|
1019 | + if ( ! is_string($this->value)) |
|
1020 | 1020 | { |
1021 | 1021 | $message = $message ?: $this->overrideError; |
1022 | 1022 | $message = sprintf( |
@@ -1042,12 +1042,12 @@ discard block |
||
1042 | 1042 | */ |
1043 | 1043 | public function regex(string $pattern, string $message = '', string $fieldName = '') : Assert |
1044 | 1044 | { |
1045 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1045 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1046 | 1046 | { |
1047 | 1047 | return $this; |
1048 | 1048 | } |
1049 | 1049 | $this->string($message, $fieldName); |
1050 | - if ( ! preg_match($pattern, $this->value) ) |
|
1050 | + if ( ! preg_match($pattern, $this->value)) |
|
1051 | 1051 | { |
1052 | 1052 | $message = $message ?: $this->overrideError; |
1053 | 1053 | $message = sprintf( |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | $this->stringify($this->value) |
1056 | 1056 | ); |
1057 | 1057 | |
1058 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
1058 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | return $this; |
@@ -1071,13 +1071,13 @@ discard block |
||
1071 | 1071 | */ |
1072 | 1072 | public function ipAddress(string $message = '', string $fieldName = '') : Assert |
1073 | 1073 | { |
1074 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1074 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1075 | 1075 | { |
1076 | 1076 | return $this; |
1077 | 1077 | } |
1078 | 1078 | $this->string($message, $fieldName); |
1079 | - $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])$/'; |
|
1080 | - if ( ! preg_match($pattern, $this->value) ) |
|
1079 | + $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])$/'; |
|
1080 | + if ( ! preg_match($pattern, $this->value)) |
|
1081 | 1081 | { |
1082 | 1082 | $message = $message ?: $this->overrideError; |
1083 | 1083 | $message = sprintf( |
@@ -1102,12 +1102,12 @@ discard block |
||
1102 | 1102 | */ |
1103 | 1103 | public function notRegex(string $pattern, string $message = '', string $fieldName = '') : Assert |
1104 | 1104 | { |
1105 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1105 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1106 | 1106 | { |
1107 | 1107 | return $this; |
1108 | 1108 | } |
1109 | 1109 | $this->string($message, $fieldName); |
1110 | - if ( preg_match($pattern, $this->value) ) |
|
1110 | + if (preg_match($pattern, $this->value)) |
|
1111 | 1111 | { |
1112 | 1112 | $message = $message ?: $this->overrideError; |
1113 | 1113 | $message = sprintf( |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | $this->stringify($this->value) |
1116 | 1116 | ); |
1117 | 1117 | |
1118 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
1118 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | return $this; |
@@ -1133,12 +1133,12 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public function length(int $length, string $message = '', string $fieldName = '', $encoding = 'utf8') : Assert |
1135 | 1135 | { |
1136 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1136 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1137 | 1137 | { |
1138 | 1138 | return $this; |
1139 | 1139 | } |
1140 | 1140 | $this->string($message, $fieldName); |
1141 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
1141 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
1142 | 1142 | { |
1143 | 1143 | $message = $message ?: $this->overrideError; |
1144 | 1144 | $message = sprintf( |
@@ -1147,7 +1147,7 @@ discard block |
||
1147 | 1147 | $length, |
1148 | 1148 | mb_strlen($this->value, $encoding) |
1149 | 1149 | ); |
1150 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
1150 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
1151 | 1151 | |
1152 | 1152 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $fieldName, $constraints); |
1153 | 1153 | } |
@@ -1168,22 +1168,22 @@ discard block |
||
1168 | 1168 | */ |
1169 | 1169 | public function minLength(int $minLength, string $message = '', string $fieldName = '', $encoding = 'utf8') : Assert |
1170 | 1170 | { |
1171 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1171 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1172 | 1172 | { |
1173 | 1173 | return $this; |
1174 | 1174 | } |
1175 | 1175 | $this->string($message, $fieldName); |
1176 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1176 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1177 | 1177 | { |
1178 | 1178 | $message = $message ?: $this->overrideError; |
1179 | - $message = sprintf( |
|
1179 | + $message = sprintf( |
|
1180 | 1180 | $message |
1181 | 1181 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1182 | 1182 | $this->stringify($this->value), |
1183 | 1183 | $minLength, |
1184 | 1184 | mb_strlen($this->value, $encoding) |
1185 | 1185 | ); |
1186 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1186 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1187 | 1187 | |
1188 | 1188 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
1189 | 1189 | } |
@@ -1204,21 +1204,21 @@ discard block |
||
1204 | 1204 | */ |
1205 | 1205 | public function maxLength(int $maxLength, string $message = '', string $fieldName = '', $encoding = 'utf8') : Assert |
1206 | 1206 | { |
1207 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1207 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1208 | 1208 | { |
1209 | 1209 | return $this; |
1210 | 1210 | } |
1211 | 1211 | $this->string($message, $fieldName); |
1212 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1212 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1213 | 1213 | { |
1214 | 1214 | $message = $message ?: $this->overrideError; |
1215 | - $message = sprintf( |
|
1215 | + $message = sprintf( |
|
1216 | 1216 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1217 | 1217 | $this->stringify($this->value), |
1218 | 1218 | $maxLength, |
1219 | 1219 | mb_strlen($this->value, $encoding) |
1220 | 1220 | ); |
1221 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1221 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1222 | 1222 | |
1223 | 1223 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
1224 | 1224 | } |
@@ -1239,35 +1239,35 @@ discard block |
||
1239 | 1239 | */ |
1240 | 1240 | public function betweenLength(int $minLength, int $maxLength, string $message = '', string $fieldName = '', $encoding = 'utf8') : Assert |
1241 | 1241 | { |
1242 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1242 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1243 | 1243 | { |
1244 | 1244 | return $this; |
1245 | 1245 | } |
1246 | 1246 | $this->string($message, $fieldName); |
1247 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1247 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1248 | 1248 | { |
1249 | 1249 | $message = $message ?: $this->overrideError; |
1250 | - $message = sprintf( |
|
1250 | + $message = sprintf( |
|
1251 | 1251 | $message |
1252 | 1252 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1253 | 1253 | $this->stringify($this->value), |
1254 | 1254 | $minLength, |
1255 | 1255 | mb_strlen($this->value, $encoding) |
1256 | 1256 | ); |
1257 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1257 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1258 | 1258 | |
1259 | 1259 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
1260 | 1260 | } |
1261 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1261 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1262 | 1262 | { |
1263 | 1263 | $message = $message ?: $this->overrideError; |
1264 | - $message = sprintf( |
|
1264 | + $message = sprintf( |
|
1265 | 1265 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1266 | 1266 | $this->stringify($this->value), |
1267 | 1267 | $maxLength, |
1268 | 1268 | mb_strlen($this->value, $encoding) |
1269 | 1269 | ); |
1270 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1270 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1271 | 1271 | |
1272 | 1272 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
1273 | 1273 | } |
@@ -1287,20 +1287,20 @@ discard block |
||
1287 | 1287 | */ |
1288 | 1288 | public function startsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
1289 | 1289 | { |
1290 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1290 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1291 | 1291 | { |
1292 | 1292 | return $this; |
1293 | 1293 | } |
1294 | 1294 | $this->string($message, $fieldName); |
1295 | - if ( mb_strpos($this->value, $needle, 0, $encoding) !== 0 ) |
|
1295 | + if (mb_strpos($this->value, $needle, 0, $encoding) !== 0) |
|
1296 | 1296 | { |
1297 | 1297 | $message = $message ?: $this->overrideError; |
1298 | - $message = sprintf( |
|
1298 | + $message = sprintf( |
|
1299 | 1299 | $message ?: 'Value "%s" does not start with "%s".', |
1300 | 1300 | $this->stringify($this->value), |
1301 | 1301 | $this->stringify($needle) |
1302 | 1302 | ); |
1303 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1303 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1304 | 1304 | |
1305 | 1305 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $fieldName, $constraints); |
1306 | 1306 | } |
@@ -1320,21 +1320,21 @@ discard block |
||
1320 | 1320 | */ |
1321 | 1321 | public function endsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
1322 | 1322 | { |
1323 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1323 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1324 | 1324 | { |
1325 | 1325 | return $this; |
1326 | 1326 | } |
1327 | 1327 | $this->string($message, $fieldName); |
1328 | 1328 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
1329 | - if ( mb_strripos($this->value, $needle, 0 , $encoding) !== $stringPosition ) |
|
1329 | + if (mb_strripos($this->value, $needle, 0, $encoding) !== $stringPosition) |
|
1330 | 1330 | { |
1331 | 1331 | $message = $message ?: $this->overrideError; |
1332 | - $message = sprintf( |
|
1332 | + $message = sprintf( |
|
1333 | 1333 | $message ?: 'Value "%s" does not end with "%s".', |
1334 | 1334 | $this->stringify($this->value), |
1335 | 1335 | $this->stringify($needle) |
1336 | 1336 | ); |
1337 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1337 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1338 | 1338 | |
1339 | 1339 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $fieldName, $constraints); |
1340 | 1340 | } |
@@ -1354,20 +1354,20 @@ discard block |
||
1354 | 1354 | */ |
1355 | 1355 | public function contains(string $needle, string $message = '', string $fieldName = '', string$encoding = 'utf8') : Assert |
1356 | 1356 | { |
1357 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1357 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1358 | 1358 | { |
1359 | 1359 | return $this; |
1360 | 1360 | } |
1361 | 1361 | $this->string($message, $fieldName); |
1362 | - if ( mb_strpos($this->value, $needle, 0, $encoding) === false ) |
|
1362 | + if (mb_strpos($this->value, $needle, 0, $encoding) === false) |
|
1363 | 1363 | { |
1364 | 1364 | $message = $message ?: $this->overrideError; |
1365 | - $message = sprintf( |
|
1365 | + $message = sprintf( |
|
1366 | 1366 | $message ?: 'Value "%s" does not contain "%s".', |
1367 | 1367 | $this->stringify($this->value), |
1368 | 1368 | $this->stringify($needle) |
1369 | 1369 | ); |
1370 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1370 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1371 | 1371 | |
1372 | 1372 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $fieldName, $constraints); |
1373 | 1373 | } |
@@ -1386,11 +1386,11 @@ discard block |
||
1386 | 1386 | */ |
1387 | 1387 | public function choice(array $choices, string $message = '', string $fieldName = '') : Assert |
1388 | 1388 | { |
1389 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1389 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1390 | 1390 | { |
1391 | 1391 | return $this; |
1392 | 1392 | } |
1393 | - if ( !in_array($this->value, $choices, true) ) |
|
1393 | + if ( ! in_array($this->value, $choices, true)) |
|
1394 | 1394 | { |
1395 | 1395 | $message = $message ?: $this->overrideError; |
1396 | 1396 | $message = sprintf( |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
1400 | 1400 | ); |
1401 | 1401 | |
1402 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, ['choices' => $choices]); |
|
1402 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, [ 'choices' => $choices ]); |
|
1403 | 1403 | } |
1404 | 1404 | |
1405 | 1405 | return $this; |
@@ -1416,7 +1416,7 @@ discard block |
||
1416 | 1416 | */ |
1417 | 1417 | public function inArray(array $choices, string $message = '', string $fieldName = '') : Assert |
1418 | 1418 | { |
1419 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1419 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1420 | 1420 | { |
1421 | 1421 | return $this; |
1422 | 1422 | } |
@@ -1435,11 +1435,11 @@ discard block |
||
1435 | 1435 | */ |
1436 | 1436 | public function numeric(string $message = '', string $fieldName = '') : Assert |
1437 | 1437 | { |
1438 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1438 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1439 | 1439 | { |
1440 | 1440 | return $this; |
1441 | 1441 | } |
1442 | - if ( ! is_numeric($this->value) ) |
|
1442 | + if ( ! is_numeric($this->value)) |
|
1443 | 1443 | { |
1444 | 1444 | $message = $message ?: $this->overrideError; |
1445 | 1445 | $message = sprintf( |
@@ -1508,11 +1508,11 @@ discard block |
||
1508 | 1508 | */ |
1509 | 1509 | public function isArray(string $message = '', string $fieldName = '') : Assert |
1510 | 1510 | { |
1511 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1511 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1512 | 1512 | { |
1513 | 1513 | return $this; |
1514 | 1514 | } |
1515 | - if ( !is_array($this->value) ) |
|
1515 | + if ( ! is_array($this->value)) |
|
1516 | 1516 | { |
1517 | 1517 | $message = $message ?: $this->overrideError; |
1518 | 1518 | $message = sprintf( |
@@ -1536,11 +1536,11 @@ discard block |
||
1536 | 1536 | */ |
1537 | 1537 | public function isTraversable(string $message = '', string $fieldName = '') : Assert |
1538 | 1538 | { |
1539 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1539 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1540 | 1540 | { |
1541 | 1541 | return $this; |
1542 | 1542 | } |
1543 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
1543 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
1544 | 1544 | { |
1545 | 1545 | $message = $message ?: $this->overrideError; |
1546 | 1546 | $message = sprintf( |
@@ -1564,11 +1564,11 @@ discard block |
||
1564 | 1564 | */ |
1565 | 1565 | public function isArrayAccessible(string $message = '', string $fieldName = '') : Assert |
1566 | 1566 | { |
1567 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1567 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1568 | 1568 | { |
1569 | 1569 | return $this; |
1570 | 1570 | } |
1571 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
1571 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
1572 | 1572 | { |
1573 | 1573 | $message = $message ?: $this->overrideError; |
1574 | 1574 | $message = sprintf( |
@@ -1593,12 +1593,12 @@ discard block |
||
1593 | 1593 | */ |
1594 | 1594 | public function keyExists($key, string $message = '', string $fieldName = '') : Assert |
1595 | 1595 | { |
1596 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1596 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1597 | 1597 | { |
1598 | 1598 | return $this; |
1599 | 1599 | } |
1600 | 1600 | $this->isArray($message, $fieldName); |
1601 | - if ( !array_key_exists($key, $this->value) ) |
|
1601 | + if ( ! array_key_exists($key, $this->value)) |
|
1602 | 1602 | { |
1603 | 1603 | $message = $message ?: $this->overrideError; |
1604 | 1604 | $message = sprintf( |
@@ -1606,7 +1606,7 @@ discard block |
||
1606 | 1606 | $this->stringify($key) |
1607 | 1607 | ); |
1608 | 1608 | |
1609 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, ['key' => $key]); |
|
1609 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
1610 | 1610 | } |
1611 | 1611 | |
1612 | 1612 | return $this; |
@@ -1623,21 +1623,21 @@ discard block |
||
1623 | 1623 | */ |
1624 | 1624 | public function keysExist(array $keys, string $message = '', string $fieldName = '') : Assert |
1625 | 1625 | { |
1626 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1626 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1627 | 1627 | { |
1628 | 1628 | return $this; |
1629 | 1629 | } |
1630 | 1630 | $this->isArray($message, $fieldName); |
1631 | - foreach ( $keys as $key ) |
|
1631 | + foreach ($keys as $key) |
|
1632 | 1632 | { |
1633 | - if ( !array_key_exists($key, $this->value) ) |
|
1633 | + if ( ! array_key_exists($key, $this->value)) |
|
1634 | 1634 | { |
1635 | 1635 | $message = $message |
1636 | 1636 | ?: sprintf( |
1637 | 1637 | 'Array does not contain an element with key "%s"', |
1638 | 1638 | $this->stringify($key) |
1639 | 1639 | ); |
1640 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, ['key' => $key]); |
|
1640 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, [ 'key' => $key ]); |
|
1641 | 1641 | } |
1642 | 1642 | } |
1643 | 1643 | |
@@ -1655,12 +1655,12 @@ discard block |
||
1655 | 1655 | */ |
1656 | 1656 | public function propertyExists($key, string $message = '', string $fieldName = '') : Assert |
1657 | 1657 | { |
1658 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1658 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1659 | 1659 | { |
1660 | 1660 | return $this; |
1661 | 1661 | } |
1662 | 1662 | $this->isObject($message, $fieldName); |
1663 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1663 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1664 | 1664 | { |
1665 | 1665 | $message = $message |
1666 | 1666 | ?: sprintf( |
@@ -1668,7 +1668,7 @@ discard block |
||
1668 | 1668 | $this->stringify($key) |
1669 | 1669 | ); |
1670 | 1670 | |
1671 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, ['key' => $key]); |
|
1671 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | return $this; |
@@ -1685,22 +1685,22 @@ discard block |
||
1685 | 1685 | */ |
1686 | 1686 | public function propertiesExist(array $keys, string $message = '', string $fieldName = '') : Assert |
1687 | 1687 | { |
1688 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1688 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1689 | 1689 | { |
1690 | 1690 | return $this; |
1691 | 1691 | } |
1692 | 1692 | $this->isObject($message, $fieldName); |
1693 | - foreach ( $keys as $key ) |
|
1693 | + foreach ($keys as $key) |
|
1694 | 1694 | { |
1695 | 1695 | // Using isset to allow resolution of magically defined properties |
1696 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1696 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1697 | 1697 | { |
1698 | 1698 | $message = $message |
1699 | 1699 | ?: sprintf( |
1700 | 1700 | 'Object does not contain a property with key "%s"', |
1701 | 1701 | $this->stringify($key) |
1702 | 1702 | ); |
1703 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, ['key' => $key]); |
|
1703 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, [ 'key' => $key ]); |
|
1704 | 1704 | } |
1705 | 1705 | } |
1706 | 1706 | |
@@ -1717,12 +1717,12 @@ discard block |
||
1717 | 1717 | */ |
1718 | 1718 | public function utf8(string $message = '', string $fieldName = '') : Assert |
1719 | 1719 | { |
1720 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1720 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1721 | 1721 | { |
1722 | 1722 | return $this; |
1723 | 1723 | } |
1724 | 1724 | $this->string($message, $fieldName); |
1725 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1725 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
1726 | 1726 | { |
1727 | 1727 | $message = $message |
1728 | 1728 | ?: sprintf( |
@@ -1747,12 +1747,12 @@ discard block |
||
1747 | 1747 | */ |
1748 | 1748 | public function ascii(string $message = '', string $fieldName = '') : Assert |
1749 | 1749 | { |
1750 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1750 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1751 | 1751 | { |
1752 | 1752 | return $this; |
1753 | 1753 | } |
1754 | 1754 | $this->string($message, $fieldName); |
1755 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1755 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
1756 | 1756 | { |
1757 | 1757 | $message = $message |
1758 | 1758 | ?: sprintf( |
@@ -1778,12 +1778,12 @@ discard block |
||
1778 | 1778 | */ |
1779 | 1779 | public function keyIsset($key, string $message = '', string $fieldName = '') : Assert |
1780 | 1780 | { |
1781 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1781 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1782 | 1782 | { |
1783 | 1783 | return $this; |
1784 | 1784 | } |
1785 | 1785 | $this->isArrayAccessible($message, $fieldName); |
1786 | - if ( !isset( $this->value[$key] ) ) |
|
1786 | + if ( ! isset($this->value[ $key ])) |
|
1787 | 1787 | { |
1788 | 1788 | $message = $message ?: $this->overrideError; |
1789 | 1789 | $message = sprintf( |
@@ -1791,7 +1791,7 @@ discard block |
||
1791 | 1791 | $this->stringify($key) |
1792 | 1792 | ); |
1793 | 1793 | |
1794 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, ['key' => $key]); |
|
1794 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, [ 'key' => $key ]); |
|
1795 | 1795 | } |
1796 | 1796 | |
1797 | 1797 | return $this; |
@@ -1809,12 +1809,12 @@ discard block |
||
1809 | 1809 | */ |
1810 | 1810 | public function notEmptyKey($key, string $message = '', string $fieldName = '') : Assert |
1811 | 1811 | { |
1812 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1812 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1813 | 1813 | { |
1814 | 1814 | return $this; |
1815 | 1815 | } |
1816 | 1816 | $this->keyIsset($key, $message, $fieldName); |
1817 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
1817 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
1818 | 1818 | |
1819 | 1819 | return $this; |
1820 | 1820 | } |
@@ -1829,11 +1829,11 @@ discard block |
||
1829 | 1829 | */ |
1830 | 1830 | public function notBlank(string $message = '', string $fieldName = '') : Assert |
1831 | 1831 | { |
1832 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1832 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1833 | 1833 | { |
1834 | 1834 | return $this; |
1835 | 1835 | } |
1836 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
1836 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
1837 | 1837 | { |
1838 | 1838 | $message = $message ?: $this->overrideError; |
1839 | 1839 | $message = sprintf( |
@@ -1858,11 +1858,11 @@ discard block |
||
1858 | 1858 | */ |
1859 | 1859 | public function isInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
1860 | 1860 | { |
1861 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1861 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1862 | 1862 | { |
1863 | 1863 | return $this; |
1864 | 1864 | } |
1865 | - if ( !( $this->value instanceof $className ) ) |
|
1865 | + if ( ! ($this->value instanceof $className)) |
|
1866 | 1866 | { |
1867 | 1867 | $message = $message ?: $this->overrideError; |
1868 | 1868 | $message = sprintf( |
@@ -1871,7 +1871,7 @@ discard block |
||
1871 | 1871 | $className |
1872 | 1872 | ); |
1873 | 1873 | |
1874 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
1874 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
1875 | 1875 | } |
1876 | 1876 | |
1877 | 1877 | return $this; |
@@ -1888,11 +1888,11 @@ discard block |
||
1888 | 1888 | */ |
1889 | 1889 | public function notIsInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
1890 | 1890 | { |
1891 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1891 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1892 | 1892 | { |
1893 | 1893 | return $this; |
1894 | 1894 | } |
1895 | - if ( $this->value instanceof $className ) |
|
1895 | + if ($this->value instanceof $className) |
|
1896 | 1896 | { |
1897 | 1897 | $message = $message ?: $this->overrideError; |
1898 | 1898 | $message = sprintf( |
@@ -1901,7 +1901,7 @@ discard block |
||
1901 | 1901 | $className |
1902 | 1902 | ); |
1903 | 1903 | |
1904 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
1904 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
1905 | 1905 | } |
1906 | 1906 | |
1907 | 1907 | return $this; |
@@ -1918,11 +1918,11 @@ discard block |
||
1918 | 1918 | */ |
1919 | 1919 | public function subclassOf(string $className, string $message = '', string $fieldName = '') : Assert |
1920 | 1920 | { |
1921 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1921 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1922 | 1922 | { |
1923 | 1923 | return $this; |
1924 | 1924 | } |
1925 | - if ( !is_subclass_of($this->value, $className) ) |
|
1925 | + if ( ! is_subclass_of($this->value, $className)) |
|
1926 | 1926 | { |
1927 | 1927 | $message = $message ?: $this->overrideError; |
1928 | 1928 | $message = sprintf( |
@@ -1931,7 +1931,7 @@ discard block |
||
1931 | 1931 | $className |
1932 | 1932 | ); |
1933 | 1933 | |
1934 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, ['class' => $className]); |
|
1934 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, [ 'class' => $className ]); |
|
1935 | 1935 | } |
1936 | 1936 | |
1937 | 1937 | return $this; |
@@ -1949,12 +1949,12 @@ discard block |
||
1949 | 1949 | */ |
1950 | 1950 | public function range(float $minValue, float $maxValue, string $message = '', string $fieldName = '') : Assert |
1951 | 1951 | { |
1952 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1952 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1953 | 1953 | { |
1954 | 1954 | return $this; |
1955 | 1955 | } |
1956 | 1956 | $this->numeric($message, $fieldName); |
1957 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
1957 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
1958 | 1958 | { |
1959 | 1959 | $message = $message ?: $this->overrideError; |
1960 | 1960 | $message = sprintf( |
@@ -1984,12 +1984,12 @@ discard block |
||
1984 | 1984 | */ |
1985 | 1985 | public function min(int $minValue, string $message = '', string $fieldName = '') : Assert |
1986 | 1986 | { |
1987 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1987 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1988 | 1988 | { |
1989 | 1989 | return $this; |
1990 | 1990 | } |
1991 | 1991 | $this->numeric($message, $fieldName); |
1992 | - if ( $this->value < $minValue ) |
|
1992 | + if ($this->value < $minValue) |
|
1993 | 1993 | { |
1994 | 1994 | $message = $message ?: $this->overrideError; |
1995 | 1995 | $message = sprintf( |
@@ -1998,7 +1998,7 @@ discard block |
||
1998 | 1998 | $this->stringify($minValue) |
1999 | 1999 | ); |
2000 | 2000 | |
2001 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, ['min' => $minValue]); |
|
2001 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, [ 'min' => $minValue ]); |
|
2002 | 2002 | } |
2003 | 2003 | |
2004 | 2004 | return $this; |
@@ -2015,12 +2015,12 @@ discard block |
||
2015 | 2015 | */ |
2016 | 2016 | public function max(int $maxValue, string $message = '', string $fieldName = '') : Assert |
2017 | 2017 | { |
2018 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2018 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2019 | 2019 | { |
2020 | 2020 | return $this; |
2021 | 2021 | } |
2022 | 2022 | $this->numeric($message, $fieldName); |
2023 | - if ( $this->value > $maxValue ) |
|
2023 | + if ($this->value > $maxValue) |
|
2024 | 2024 | { |
2025 | 2025 | $message = $message ?: $this->overrideError; |
2026 | 2026 | $message = sprintf( |
@@ -2029,7 +2029,7 @@ discard block |
||
2029 | 2029 | $this->stringify($maxValue) |
2030 | 2030 | ); |
2031 | 2031 | |
2032 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, ['max' => $maxValue]); |
|
2032 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, [ 'max' => $maxValue ]); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | return $this; |
@@ -2045,13 +2045,13 @@ discard block |
||
2045 | 2045 | */ |
2046 | 2046 | public function file(string $message = '', string $fieldName = '') : Assert |
2047 | 2047 | { |
2048 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2048 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2049 | 2049 | { |
2050 | 2050 | return $this; |
2051 | 2051 | } |
2052 | 2052 | $this->string($message, $fieldName); |
2053 | 2053 | $this->notEmpty($message, $fieldName); |
2054 | - if ( !is_file($this->value) ) |
|
2054 | + if ( ! is_file($this->value)) |
|
2055 | 2055 | { |
2056 | 2056 | $message = $message ?: $this->overrideError; |
2057 | 2057 | $message = sprintf( |
@@ -2075,13 +2075,13 @@ discard block |
||
2075 | 2075 | */ |
2076 | 2076 | public function fileOrDirectoryExists(string $message = '', string $fieldName = '') : Assert |
2077 | 2077 | { |
2078 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2078 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2079 | 2079 | { |
2080 | 2080 | return $this; |
2081 | 2081 | } |
2082 | 2082 | $this->string($message, $fieldName); |
2083 | 2083 | $this->notEmpty($message, $fieldName); |
2084 | - if ( ! file_exists($this->value) ) |
|
2084 | + if ( ! file_exists($this->value)) |
|
2085 | 2085 | { |
2086 | 2086 | $message = $message ?: $this->overrideError; |
2087 | 2087 | $message = sprintf( |
@@ -2105,12 +2105,12 @@ discard block |
||
2105 | 2105 | */ |
2106 | 2106 | public function directory(string $message = '', string $fieldName = '') : Assert |
2107 | 2107 | { |
2108 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2108 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2109 | 2109 | { |
2110 | 2110 | return $this; |
2111 | 2111 | } |
2112 | 2112 | $this->string($message, $fieldName); |
2113 | - if ( !is_dir($this->value) ) |
|
2113 | + if ( ! is_dir($this->value)) |
|
2114 | 2114 | { |
2115 | 2115 | $message = $message ?: $this->overrideError; |
2116 | 2116 | $message = sprintf( |
@@ -2134,12 +2134,12 @@ discard block |
||
2134 | 2134 | */ |
2135 | 2135 | public function readable(string $message = '', string $fieldName = '') : Assert |
2136 | 2136 | { |
2137 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2137 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2138 | 2138 | { |
2139 | 2139 | return $this; |
2140 | 2140 | } |
2141 | 2141 | $this->string($message, $fieldName); |
2142 | - if ( !is_readable($this->value) ) |
|
2142 | + if ( ! is_readable($this->value)) |
|
2143 | 2143 | { |
2144 | 2144 | $message = $message ?: $this->overrideError; |
2145 | 2145 | $message = sprintf( |
@@ -2163,12 +2163,12 @@ discard block |
||
2163 | 2163 | */ |
2164 | 2164 | public function writeable(string $message = '', string $fieldName = '') : Assert |
2165 | 2165 | { |
2166 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2166 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2167 | 2167 | { |
2168 | 2168 | return $this; |
2169 | 2169 | } |
2170 | 2170 | $this->string($message, $fieldName); |
2171 | - if ( !is_writeable($this->value) ) |
|
2171 | + if ( ! is_writeable($this->value)) |
|
2172 | 2172 | { |
2173 | 2173 | $message = $message ?: $this->overrideError; |
2174 | 2174 | $message = sprintf( |
@@ -2192,12 +2192,12 @@ discard block |
||
2192 | 2192 | */ |
2193 | 2193 | public function email(string $message = '', string $fieldName = '') : Assert |
2194 | 2194 | { |
2195 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2195 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2196 | 2196 | { |
2197 | 2197 | return $this; |
2198 | 2198 | } |
2199 | 2199 | $this->string($message, $fieldName); |
2200 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
2200 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
2201 | 2201 | { |
2202 | 2202 | $message = $message ?: $this->overrideError; |
2203 | 2203 | $message = sprintf( |
@@ -2211,7 +2211,7 @@ discard block |
||
2211 | 2211 | { |
2212 | 2212 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2213 | 2213 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
2214 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
2214 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
2215 | 2215 | { |
2216 | 2216 | $message = $message ?: $this->overrideError; |
2217 | 2217 | $message = sprintf( |
@@ -2235,7 +2235,7 @@ discard block |
||
2235 | 2235 | */ |
2236 | 2236 | public function emailPrefix(string $message = '', string $fieldName = '') : Assert |
2237 | 2237 | { |
2238 | - $this->value($this->value . '@example.com'); |
|
2238 | + $this->value($this->value.'@example.com'); |
|
2239 | 2239 | |
2240 | 2240 | return $this->email($message, $fieldName); |
2241 | 2241 | } |
@@ -2256,12 +2256,12 @@ discard block |
||
2256 | 2256 | */ |
2257 | 2257 | public function url(string $message = '', string $fieldName = '') : Assert |
2258 | 2258 | { |
2259 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2259 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2260 | 2260 | { |
2261 | 2261 | return $this; |
2262 | 2262 | } |
2263 | 2263 | $this->string($message, $fieldName); |
2264 | - $protocols = ['http', 'https']; |
|
2264 | + $protocols = [ 'http', 'https' ]; |
|
2265 | 2265 | $pattern = '~^ |
2266 | 2266 | (%s):// # protocol |
2267 | 2267 | ( |
@@ -2276,8 +2276,8 @@ discard block |
||
2276 | 2276 | (:[0-9]+)? # a port (optional) |
2277 | 2277 | (/?|/\S+) # a /, nothing or a / with something |
2278 | 2278 | $~ixu'; |
2279 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2280 | - if ( !preg_match($pattern, $this->value) ) |
|
2279 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2280 | + if ( ! preg_match($pattern, $this->value)) |
|
2281 | 2281 | { |
2282 | 2282 | $message = $message ?: $this->overrideError; |
2283 | 2283 | $message = sprintf( |
@@ -2304,13 +2304,13 @@ discard block |
||
2304 | 2304 | */ |
2305 | 2305 | public function domainName(string $message = '', string $fieldName = '') : Assert |
2306 | 2306 | { |
2307 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2307 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2308 | 2308 | { |
2309 | 2309 | return $this; |
2310 | 2310 | } |
2311 | 2311 | $this->string($message, $fieldName); |
2312 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2313 | - if ( ! preg_match($pattern, $this->value) ) |
|
2312 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2313 | + if ( ! preg_match($pattern, $this->value)) |
|
2314 | 2314 | { |
2315 | 2315 | $message = $message ?: $this->overrideError; |
2316 | 2316 | $message = sprintf( |
@@ -2334,7 +2334,7 @@ discard block |
||
2334 | 2334 | */ |
2335 | 2335 | public function ausMobile(string $message = '', string $fieldName = '') : Assert |
2336 | 2336 | { |
2337 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2337 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2338 | 2338 | { |
2339 | 2339 | return $this; |
2340 | 2340 | } |
@@ -2342,7 +2342,7 @@ discard block |
||
2342 | 2342 | { |
2343 | 2343 | $this->regex('/^04[0-9]{8})$/', $message, $fieldName); |
2344 | 2344 | } |
2345 | - catch ( AssertionFailedException $e ) |
|
2345 | + catch (AssertionFailedException $e) |
|
2346 | 2346 | { |
2347 | 2347 | $message = $message ?: $this->overrideError; |
2348 | 2348 | $message = sprintf( |
@@ -2367,7 +2367,7 @@ discard block |
||
2367 | 2367 | */ |
2368 | 2368 | public function alnum(string $message = '', string $fieldName = '') : Assert |
2369 | 2369 | { |
2370 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2370 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2371 | 2371 | { |
2372 | 2372 | return $this; |
2373 | 2373 | } |
@@ -2400,11 +2400,11 @@ discard block |
||
2400 | 2400 | */ |
2401 | 2401 | public function true(string $message = '', string $fieldName = '') : Assert |
2402 | 2402 | { |
2403 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2403 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2404 | 2404 | { |
2405 | 2405 | return $this; |
2406 | 2406 | } |
2407 | - if ( $this->value !== true ) |
|
2407 | + if ($this->value !== true) |
|
2408 | 2408 | { |
2409 | 2409 | $message = $message ?: $this->overrideError; |
2410 | 2410 | $message = sprintf( |
@@ -2428,11 +2428,11 @@ discard block |
||
2428 | 2428 | */ |
2429 | 2429 | public function truthy(string $message = '', string $fieldName = '') : Assert |
2430 | 2430 | { |
2431 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2431 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2432 | 2432 | { |
2433 | 2433 | return $this; |
2434 | 2434 | } |
2435 | - if ( ! $this->value ) |
|
2435 | + if ( ! $this->value) |
|
2436 | 2436 | { |
2437 | 2437 | $message = $message ?: $this->overrideError; |
2438 | 2438 | $message = sprintf( |
@@ -2456,11 +2456,11 @@ discard block |
||
2456 | 2456 | */ |
2457 | 2457 | public function false(string $message = '', string $fieldName = '') : Assert |
2458 | 2458 | { |
2459 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2459 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2460 | 2460 | { |
2461 | 2461 | return $this; |
2462 | 2462 | } |
2463 | - if ( $this->value !== false ) |
|
2463 | + if ($this->value !== false) |
|
2464 | 2464 | { |
2465 | 2465 | $message = $message ?: $this->overrideError; |
2466 | 2466 | $message = sprintf( |
@@ -2484,11 +2484,11 @@ discard block |
||
2484 | 2484 | */ |
2485 | 2485 | public function notFalse(string $message = '', string $fieldName = '') : Assert |
2486 | 2486 | { |
2487 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2487 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2488 | 2488 | { |
2489 | 2489 | return $this; |
2490 | 2490 | } |
2491 | - if ( $this->value === false ) |
|
2491 | + if ($this->value === false) |
|
2492 | 2492 | { |
2493 | 2493 | $message = $message ?: $this->overrideError; |
2494 | 2494 | $message = sprintf( |
@@ -2512,11 +2512,11 @@ discard block |
||
2512 | 2512 | */ |
2513 | 2513 | public function classExists(string $message = '', string $fieldName = '') : Assert |
2514 | 2514 | { |
2515 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2515 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2516 | 2516 | { |
2517 | 2517 | return $this; |
2518 | 2518 | } |
2519 | - if ( !class_exists($this->value) ) |
|
2519 | + if ( ! class_exists($this->value)) |
|
2520 | 2520 | { |
2521 | 2521 | $message = $message ?: $this->overrideError; |
2522 | 2522 | $message = sprintf( |
@@ -2540,12 +2540,12 @@ discard block |
||
2540 | 2540 | */ |
2541 | 2541 | public function implementsInterface(string $interfaceName, string $message = '', string $fieldName = '') : Assert |
2542 | 2542 | { |
2543 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2543 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2544 | 2544 | { |
2545 | 2545 | return $this; |
2546 | 2546 | } |
2547 | 2547 | $reflection = new \ReflectionClass($this->value); |
2548 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
2548 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
2549 | 2549 | { |
2550 | 2550 | $message = $message ?: $this->overrideError; |
2551 | 2551 | $message = sprintf( |
@@ -2554,7 +2554,7 @@ discard block |
||
2554 | 2554 | $this->stringify($interfaceName) |
2555 | 2555 | ); |
2556 | 2556 | |
2557 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, ['interface' => $interfaceName]); |
|
2557 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, [ 'interface' => $interfaceName ]); |
|
2558 | 2558 | } |
2559 | 2559 | |
2560 | 2560 | return $this; |
@@ -2576,11 +2576,11 @@ discard block |
||
2576 | 2576 | */ |
2577 | 2577 | public function isJsonString(string $message = '', string $fieldName = '') : Assert |
2578 | 2578 | { |
2579 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2579 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2580 | 2580 | { |
2581 | 2581 | return $this; |
2582 | 2582 | } |
2583 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
2583 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
2584 | 2584 | { |
2585 | 2585 | $message = $message ?: $this->overrideError; |
2586 | 2586 | $message = sprintf( |
@@ -2606,16 +2606,16 @@ discard block |
||
2606 | 2606 | */ |
2607 | 2607 | public function uuid(string $message = '', string $fieldName = '') : Assert |
2608 | 2608 | { |
2609 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2609 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2610 | 2610 | { |
2611 | 2611 | return $this; |
2612 | 2612 | } |
2613 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
2614 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
2613 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
2614 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
2615 | 2615 | { |
2616 | 2616 | return $this; |
2617 | 2617 | } |
2618 | - 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) ) |
|
2618 | + 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)) |
|
2619 | 2619 | { |
2620 | 2620 | $message = $message ?: $this->overrideError; |
2621 | 2621 | $message = sprintf( |
@@ -2646,11 +2646,11 @@ discard block |
||
2646 | 2646 | */ |
2647 | 2647 | public function samAccountName(string $message = '', string $fieldName = '') : Assert |
2648 | 2648 | { |
2649 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2649 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2650 | 2650 | { |
2651 | 2651 | return $this; |
2652 | 2652 | } |
2653 | - if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
2653 | + if ( ! preg_match('/^([a-z0-9]{4,20})$/', $this->value)) |
|
2654 | 2654 | { |
2655 | 2655 | $message = $message ?: $this->overrideError; |
2656 | 2656 | $message = sprintf( |
@@ -2674,7 +2674,7 @@ discard block |
||
2674 | 2674 | */ |
2675 | 2675 | public function userPrincipalName(string $message = '', string $fieldName = '') : Assert |
2676 | 2676 | { |
2677 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2677 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2678 | 2678 | { |
2679 | 2679 | return $this; |
2680 | 2680 | } |
@@ -2708,11 +2708,11 @@ discard block |
||
2708 | 2708 | */ |
2709 | 2709 | public function count(int $count, string $message = '', string $fieldName = '') : Assert |
2710 | 2710 | { |
2711 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2711 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2712 | 2712 | { |
2713 | 2713 | return $this; |
2714 | 2714 | } |
2715 | - if ( $count !== count($this->value) ) |
|
2715 | + if ($count !== count($this->value)) |
|
2716 | 2716 | { |
2717 | 2717 | $message = $message ?: $this->overrideError; |
2718 | 2718 | $message = sprintf( |
@@ -2721,7 +2721,7 @@ discard block |
||
2721 | 2721 | $this->stringify($count) |
2722 | 2722 | ); |
2723 | 2723 | |
2724 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, ['count' => $count]); |
|
2724 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, [ 'count' => $count ]); |
|
2725 | 2725 | } |
2726 | 2726 | |
2727 | 2727 | return $this; |
@@ -2735,25 +2735,25 @@ discard block |
||
2735 | 2735 | */ |
2736 | 2736 | protected function doAllOrNullOr($func, $args) : bool |
2737 | 2737 | { |
2738 | - if ( $this->nullOr && is_null($this->value) ) |
|
2738 | + if ($this->nullOr && is_null($this->value)) |
|
2739 | 2739 | { |
2740 | 2740 | return true; |
2741 | 2741 | } |
2742 | - if ( $this->emptyOr && empty($this->value) ) |
|
2742 | + if ($this->emptyOr && empty($this->value)) |
|
2743 | 2743 | { |
2744 | 2744 | return true; |
2745 | 2745 | } |
2746 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
2746 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
2747 | 2747 | { |
2748 | - foreach ( $this->value as $idx => $value ) |
|
2748 | + foreach ($this->value as $idx => $value) |
|
2749 | 2749 | { |
2750 | 2750 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
2751 | - call_user_func_array([$object, $func], $args); |
|
2751 | + call_user_func_array([ $object, $func ], $args); |
|
2752 | 2752 | } |
2753 | 2753 | return true; |
2754 | 2754 | } |
2755 | 2755 | |
2756 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
2756 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
2757 | 2757 | } |
2758 | 2758 | |
2759 | 2759 | /** |
@@ -2767,12 +2767,12 @@ discard block |
||
2767 | 2767 | */ |
2768 | 2768 | public function choicesNotEmpty(array $choices, string $message = '', string $fieldName = '') : Assert |
2769 | 2769 | { |
2770 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2770 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2771 | 2771 | { |
2772 | 2772 | return $this; |
2773 | 2773 | } |
2774 | 2774 | $this->notEmpty($message, $fieldName); |
2775 | - foreach ( $choices as $choice ) |
|
2775 | + foreach ($choices as $choice) |
|
2776 | 2776 | { |
2777 | 2777 | $this->notEmptyKey($choice, $message, $fieldName); |
2778 | 2778 | } |
@@ -2791,12 +2791,12 @@ discard block |
||
2791 | 2791 | */ |
2792 | 2792 | public function methodExists($object, string $message = '', string $fieldName = '') : Assert |
2793 | 2793 | { |
2794 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2794 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2795 | 2795 | { |
2796 | 2796 | return $this; |
2797 | 2797 | } |
2798 | 2798 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $fieldName); |
2799 | - if ( !method_exists($object, $this->value) ) |
|
2799 | + if ( ! method_exists($object, $this->value)) |
|
2800 | 2800 | { |
2801 | 2801 | $message = $message ?: $this->overrideError; |
2802 | 2802 | $message = sprintf( |
@@ -2820,11 +2820,11 @@ discard block |
||
2820 | 2820 | */ |
2821 | 2821 | public function isObject(string $message = '', string $fieldName = '') : Assert |
2822 | 2822 | { |
2823 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2823 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2824 | 2824 | { |
2825 | 2825 | return $this; |
2826 | 2826 | } |
2827 | - if ( !is_object($this->value) ) |
|
2827 | + if ( ! is_object($this->value)) |
|
2828 | 2828 | { |
2829 | 2829 | $message = $message ?: $this->overrideError; |
2830 | 2830 | $message = sprintf( |
@@ -2846,32 +2846,32 @@ discard block |
||
2846 | 2846 | */ |
2847 | 2847 | private function stringify($value) : string |
2848 | 2848 | { |
2849 | - if ( is_bool($value) ) |
|
2849 | + if (is_bool($value)) |
|
2850 | 2850 | { |
2851 | 2851 | return $value ? '<TRUE>' : '<FALSE>'; |
2852 | 2852 | } |
2853 | - if ( is_scalar($value) ) |
|
2853 | + if (is_scalar($value)) |
|
2854 | 2854 | { |
2855 | 2855 | $val = (string)$value; |
2856 | - if ( strlen($val) > 100 ) |
|
2856 | + if (strlen($val) > 100) |
|
2857 | 2857 | { |
2858 | - $val = substr($val, 0, 97) . '...'; |
|
2858 | + $val = substr($val, 0, 97).'...'; |
|
2859 | 2859 | } |
2860 | 2860 | return $val; |
2861 | 2861 | } |
2862 | - if ( is_array($value) ) |
|
2862 | + if (is_array($value)) |
|
2863 | 2863 | { |
2864 | 2864 | return '<ARRAY>'; |
2865 | 2865 | } |
2866 | - if ( is_object($value) ) |
|
2866 | + if (is_object($value)) |
|
2867 | 2867 | { |
2868 | 2868 | return get_class($value); |
2869 | 2869 | } |
2870 | - if ( is_resource($value) ) |
|
2870 | + if (is_resource($value)) |
|
2871 | 2871 | { |
2872 | 2872 | return '<RESOURCE>'; |
2873 | 2873 | } |
2874 | - if ( $value === null ) |
|
2874 | + if ($value === null) |
|
2875 | 2875 | { |
2876 | 2876 | return '<NULL>'; |
2877 | 2877 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param Closure $test |
43 | 43 | * @param string $suiteName |
44 | 44 | * @param string $successMessage |
45 | - * @param int|null $exceptionCode |
|
45 | + * @param integer $exceptionCode |
|
46 | 46 | * @param string $exceptionClass |
47 | 47 | * @return Suite |
48 | 48 | * @throws AssertionFailedException |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $testName |
167 | 167 | * @param Closure $test |
168 | 168 | * @param string $successMessage |
169 | - * @param int|null $exceptionCode |
|
169 | + * @param integer $exceptionCode |
|
170 | 170 | * @param string $exceptionClass |
171 | 171 | * @return Suite |
172 | 172 | * @throws AssertionFailedException |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param string $testName |
252 | 252 | * @param Closure $test |
253 | 253 | * @param string $successMessage |
254 | - * @param int|null $exceptionCode |
|
254 | + * @param integer $exceptionCode |
|
255 | 255 | * @param string $exceptionClass |
256 | 256 | * @throws AssertionFailedException |
257 | 257 | */ |
@@ -707,8 +707,8 @@ discard block |
||
707 | 707 | /** |
708 | 708 | * Log messages to resource |
709 | 709 | * |
710 | - * @param mixed $level The level of the log message |
|
711 | - * @param string|object $message If an object is passed it must implement __toString() |
|
710 | + * @param string $level The level of the log message |
|
711 | + * @param string $message If an object is passed it must implement __toString() |
|
712 | 712 | * @param array $context Placeholders to be substituted in the message |
713 | 713 | */ |
714 | 714 | public function log($level, $message, array $context=[]) |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
787 | - * @return mixed|resource |
|
787 | + * @return resource |
|
788 | 788 | * @throws \Exception |
789 | 789 | */ |
790 | 790 | protected function getResource() |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | protected static $currentSuite = self::DEFAULT_SUITE; |
13 | 13 | |
14 | 14 | /** @var Suite[] */ |
15 | - protected static $suites = []; |
|
15 | + protected static $suites = [ ]; |
|
16 | 16 | |
17 | 17 | /** @var Logger $logger */ |
18 | 18 | public static $logger = null; |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | * @param string $suiteName |
30 | 30 | * @return Suite |
31 | 31 | */ |
32 | - public static function suite(string $suiteName='') : Suite |
|
32 | + public static function suite(string $suiteName = '') : Suite |
|
33 | 33 | { |
34 | 34 | $suiteName = $suiteName ?: static::$currentSuite; |
35 | - static::$suites[$suiteName] = new Suite(); |
|
35 | + static::$suites[ $suiteName ] = new Suite(); |
|
36 | 36 | |
37 | - return static::$suites[$suiteName]; |
|
37 | + return static::$suites[ $suiteName ]; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Suite |
48 | 48 | * @throws AssertionFailedException |
49 | 49 | */ |
50 | - public static function test(string $testName, Closure $test, string $suiteName='', string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite |
|
50 | + public static function test(string $testName, Closure $test, string $suiteName = '', string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite |
|
51 | 51 | { |
52 | 52 | Assert::that($successMessage)->notEmpty(); |
53 | 53 | Assert::that($test)->isCallable(); |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @param string $suiteName |
61 | 61 | * @param string $testName |
62 | 62 | */ |
63 | - public static function run(string $suiteName='', string $testName='') |
|
63 | + public static function run(string $suiteName = '', string $testName = '') |
|
64 | 64 | { |
65 | - $suites = static::$suites; |
|
66 | - if ( ! empty($suiteName) ) |
|
65 | + $suites = static::$suites; |
|
66 | + if ( ! empty($suiteName)) |
|
67 | 67 | { |
68 | 68 | Assert::that($suites)->keyExists($suiteName, "The test suite ({$suiteName}) has not been loaded"); |
69 | - $suites = [$suites[$suiteName]]; |
|
69 | + $suites = [ $suites[ $suiteName ] ]; |
|
70 | 70 | } |
71 | - foreach ( $suites as $suite ) |
|
71 | + foreach ($suites as $suite) |
|
72 | 72 | { |
73 | 73 | $suite->run($testName); |
74 | 74 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function getLogger() : Logger |
81 | 81 | { |
82 | - if ( ! static::$logger ) |
|
82 | + if ( ! static::$logger) |
|
83 | 83 | { |
84 | 84 | static::$logger = new Logger(); |
85 | 85 | } |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @param string $suiteName |
92 | 92 | * @return Suite |
93 | 93 | */ |
94 | - protected static function getSuite(string $suiteName='') : Suite |
|
94 | + protected static function getSuite(string $suiteName = '') : Suite |
|
95 | 95 | { |
96 | - $suiteName = $suiteName ?: static::$currentSuite; |
|
97 | - if ( ! array_key_exists($suiteName, static::$suites) ) |
|
96 | + $suiteName = $suiteName ?: static::$currentSuite; |
|
97 | + if ( ! array_key_exists($suiteName, static::$suites)) |
|
98 | 98 | { |
99 | 99 | return static::suite($suiteName); |
100 | 100 | } |
101 | 101 | |
102 | - return static::$suites[$suiteName]; |
|
102 | + return static::$suites[ $suiteName ]; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | class Suite |
108 | 108 | { |
109 | 109 | /** @var Test[] */ |
110 | - protected $tests = []; |
|
110 | + protected $tests = [ ]; |
|
111 | 111 | |
112 | 112 | /** @var mixed[] */ |
113 | - protected $fixtures = []; |
|
113 | + protected $fixtures = [ ]; |
|
114 | 114 | |
115 | 115 | /** @var Logger */ |
116 | 116 | protected $logger = null; |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | /** |
119 | 119 | * @param string $filter |
120 | 120 | */ |
121 | - public function run(string $filter='') |
|
121 | + public function run(string $filter = '') |
|
122 | 122 | { |
123 | - foreach ( $this->tests as $test => $testCase ) |
|
123 | + foreach ($this->tests as $test => $testCase) |
|
124 | 124 | { |
125 | - $testName = $testCase->getTestName(); |
|
126 | - if ( $filter && $test !== $filter ) |
|
125 | + $testName = $testCase->getTestName(); |
|
126 | + if ($filter && $test !== $filter) |
|
127 | 127 | { |
128 | 128 | continue; |
129 | 129 | } |
@@ -131,33 +131,33 @@ discard block |
||
131 | 131 | { |
132 | 132 | $this->getLogger()->info("[{$testName}] - Starting..."); |
133 | 133 | $testCase->runTest($this); |
134 | - $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); |
|
134 | + $this->getLogger()->info("[{$testName}] - ".$testCase->getSuccessMessage()); |
|
135 | 135 | } |
136 | - catch ( \Exception $e ) |
|
136 | + catch (\Exception $e) |
|
137 | 137 | { |
138 | 138 | $expectedCode = $testCase->getExceptionCode(); |
139 | 139 | $expectedClass = $testCase->getExceptionType(); |
140 | 140 | $code = $e->getCode(); |
141 | 141 | $exception = get_class($e); |
142 | - if ( ! $expectedClass && ! $expectedCode ) |
|
142 | + if ( ! $expectedClass && ! $expectedCode) |
|
143 | 143 | { |
144 | - $this->getLogger()->error($e->getMessage(), [compact('testName'), $e]); |
|
144 | + $this->getLogger()->error($e->getMessage(), [ compact('testName'), $e ]); |
|
145 | 145 | |
146 | 146 | continue; |
147 | 147 | } |
148 | - if ( $expectedCode && $expectedCode !== $code ) |
|
148 | + if ($expectedCode && $expectedCode !== $code) |
|
149 | 149 | { |
150 | - $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [compact('testName'), $e]); |
|
150 | + $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [ compact('testName'), $e ]); |
|
151 | 151 | |
152 | 152 | continue; |
153 | 153 | } |
154 | - if ( $expectedClass && $expectedClass !== $exception ) |
|
154 | + if ($expectedClass && $expectedClass !== $exception) |
|
155 | 155 | { |
156 | - $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [compact('testName'), $e]); |
|
156 | + $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [ compact('testName'), $e ]); |
|
157 | 157 | |
158 | 158 | continue; |
159 | 159 | } |
160 | - $this->getLogger()->info("[{$test}] - " . $testCase->getSuccessMessage()); |
|
160 | + $this->getLogger()->info("[{$test}] - ".$testCase->getSuccessMessage()); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | * @return Suite |
172 | 172 | * @throws AssertionFailedException |
173 | 173 | */ |
174 | - public function test(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite |
|
174 | + public function test(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite |
|
175 | 175 | { |
176 | - $this->tests[] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); |
|
176 | + $this->tests[ ] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); |
|
177 | 177 | |
178 | 178 | return $this; |
179 | 179 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function fixture(string $fixtureName, $value) : Suite |
187 | 187 | { |
188 | - $this->fixtures[$fixtureName] = $value; |
|
188 | + $this->fixtures[ $fixtureName ] = $value; |
|
189 | 189 | |
190 | 190 | return $this; |
191 | 191 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | { |
200 | 200 | Assert::that($this->fixtures)->keyExists($fixtureName, "The fixture ({$fixtureName}) does not exist."); |
201 | 201 | |
202 | - return $this->fixtures[$fixtureName]; |
|
202 | + return $this->fixtures[ $fixtureName ]; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function getLogger() : Logger |
221 | 221 | { |
222 | - if ( ! $this->logger ) |
|
222 | + if ( ! $this->logger) |
|
223 | 223 | { |
224 | 224 | $this->logger = new Logger(); |
225 | 225 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @param string $exceptionClass |
256 | 256 | * @throws AssertionFailedException |
257 | 257 | */ |
258 | - public function __construct(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') |
|
258 | + public function __construct(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') |
|
259 | 259 | { |
260 | 260 | $this->setTestName($testName); |
261 | 261 | $this->setTest($test); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function getSuccessMessage() : string |
292 | 292 | { |
293 | - if ( ! $this->successMessage ) |
|
293 | + if ( ! $this->successMessage) |
|
294 | 294 | { |
295 | 295 | return "Successfully run {$this->testName}"; |
296 | 296 | } |
@@ -443,21 +443,21 @@ discard block |
||
443 | 443 | /** |
444 | 444 | * @var array $logLevels List of supported levels |
445 | 445 | */ |
446 | - static protected $logLevels = [ |
|
447 | - self::EMERGENCY => [1, self::WHITE, self::RED, self::DEFAULT, 'EMERG'], |
|
448 | - self::ALERT => [2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT'], |
|
449 | - self::CRITICAL => [3, self::RED, self::DEFAULT, self::BOLD , 'CRIT'], |
|
450 | - self::ERROR => [4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR'], |
|
451 | - self::WARNING => [5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN'], |
|
452 | - self::NOTICE => [6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE'], |
|
453 | - self::INFO => [7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO'], |
|
454 | - self::DEBUG => [8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG'], |
|
446 | + static protected $logLevels = [ |
|
447 | + self::EMERGENCY => [ 1, self::WHITE, self::RED, self::DEFAULT, 'EMERG' ], |
|
448 | + self::ALERT => [ 2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT' ], |
|
449 | + self::CRITICAL => [ 3, self::RED, self::DEFAULT, self::BOLD, 'CRIT' ], |
|
450 | + self::ERROR => [ 4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR' ], |
|
451 | + self::WARNING => [ 5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN' ], |
|
452 | + self::NOTICE => [ 6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE' ], |
|
453 | + self::INFO => [ 7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO' ], |
|
454 | + self::DEBUG => [ 8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG' ], |
|
455 | 455 | ]; |
456 | 456 | |
457 | 457 | /** |
458 | 458 | * @var array |
459 | 459 | */ |
460 | - static protected $colours = [ |
|
460 | + static protected $colours = [ |
|
461 | 461 | 'fore' => [ |
462 | 462 | self::BLACK => '0;30', |
463 | 463 | self::DARK_GRAY => '1;30', |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | self::CYAN => '46', |
489 | 489 | self::LIGHT_GRAY => '47', |
490 | 490 | ], |
491 | - self::BOLD => [], |
|
491 | + self::BOLD => [ ], |
|
492 | 492 | ]; |
493 | 493 | |
494 | 494 | /** |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * @param bool $gzipFile |
499 | 499 | * @param bool $addDate |
500 | 500 | */ |
501 | - public function __construct($resource=STDOUT, string $level=self::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true) |
|
501 | + public function __construct($resource = STDOUT, string $level = self::INFO, bool $useLocking = false, bool $gzipFile = false, bool $addDate = true) |
|
502 | 502 | { |
503 | 503 | $this->resource = $resource; |
504 | 504 | $this->setLogLevel($level); |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @param string $message |
514 | 514 | * @param array $context |
515 | 515 | */ |
516 | - public function emergency(string $message, array $context=[]) |
|
516 | + public function emergency(string $message, array $context = [ ]) |
|
517 | 517 | { |
518 | 518 | $this->log(self::EMERGENCY, $message, $context); |
519 | 519 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | * @param string $message |
528 | 528 | * @param array $context |
529 | 529 | */ |
530 | - public function alert(string $message, array $context=[]) |
|
530 | + public function alert(string $message, array $context = [ ]) |
|
531 | 531 | { |
532 | 532 | $this->log(self::ALERT, $message, $context); |
533 | 533 | } |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * @param string $message |
541 | 541 | * @param array $context |
542 | 542 | */ |
543 | - public function critical(string $message, array $context=[]) |
|
543 | + public function critical(string $message, array $context = [ ]) |
|
544 | 544 | { |
545 | 545 | $this->log(self::CRITICAL, $message, $context); |
546 | 546 | } |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | * @param string $message |
553 | 553 | * @param array $context |
554 | 554 | */ |
555 | - public function error(string $message, array $context=[]) |
|
555 | + public function error(string $message, array $context = [ ]) |
|
556 | 556 | { |
557 | 557 | $this->log(self::ERROR, $message, $context); |
558 | 558 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @param string $message |
567 | 567 | * @param array $context |
568 | 568 | */ |
569 | - public function warning(string $message, array $context=[]) |
|
569 | + public function warning(string $message, array $context = [ ]) |
|
570 | 570 | { |
571 | 571 | $this->log(self::WARNING, $message, $context); |
572 | 572 | } |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | * @param string $message |
578 | 578 | * @param array $context |
579 | 579 | */ |
580 | - public function notice(string $message, array $context=[]) |
|
580 | + public function notice(string $message, array $context = [ ]) |
|
581 | 581 | { |
582 | 582 | $this->log(self::NOTICE, $message, $context); |
583 | 583 | } |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @param string $message |
591 | 591 | * @param array $context |
592 | 592 | */ |
593 | - public function info(string $message, array $context=[]) |
|
593 | + public function info(string $message, array $context = [ ]) |
|
594 | 594 | { |
595 | 595 | $this->log(self::INFO, $message, $context); |
596 | 596 | } |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | * @param string $message |
602 | 602 | * @param array $context |
603 | 603 | */ |
604 | - public function debug(string $message, array $context=[]) |
|
604 | + public function debug(string $message, array $context = [ ]) |
|
605 | 605 | { |
606 | 606 | $this->log(self::DEBUG, $message, $context); |
607 | 607 | } |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | */ |
613 | 613 | public function setLogFile($resource) : Logger |
614 | 614 | { |
615 | - $this->resource = $resource; |
|
615 | + $this->resource = $resource; |
|
616 | 616 | |
617 | 617 | return $this; |
618 | 618 | } |
@@ -624,23 +624,23 @@ discard block |
||
624 | 624 | * @param bool $bold |
625 | 625 | * @return string |
626 | 626 | */ |
627 | - public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
627 | + public static function addColour(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
628 | 628 | { |
629 | 629 | // todo: support bold |
630 | 630 | unset($bold); |
631 | 631 | $coloredString = ''; |
632 | 632 | // Check if given foreground color found |
633 | - if ( isset(static::$colours['fore'][$foregroundColor]) ) |
|
633 | + if (isset(static::$colours[ 'fore' ][ $foregroundColor ])) |
|
634 | 634 | { |
635 | - $coloredString .= "\033[" . static::$colours['fore'][$foregroundColor] . "m"; |
|
635 | + $coloredString .= "\033[".static::$colours[ 'fore' ][ $foregroundColor ]."m"; |
|
636 | 636 | } |
637 | 637 | // Check if given background color found |
638 | - if ( isset(static::$colours['back'][$backgroundColor]) ) |
|
638 | + if (isset(static::$colours[ 'back' ][ $backgroundColor ])) |
|
639 | 639 | { |
640 | - $coloredString .= "\033[" . static::$colours['back'][$backgroundColor] . "m"; |
|
640 | + $coloredString .= "\033[".static::$colours[ 'back' ][ $backgroundColor ]."m"; |
|
641 | 641 | } |
642 | 642 | // Add string and end coloring |
643 | - $coloredString .= $string . "\033[0m"; |
|
643 | + $coloredString .= $string."\033[0m"; |
|
644 | 644 | |
645 | 645 | return $coloredString; |
646 | 646 | } |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | * @param bool $bold |
653 | 653 | * @return string |
654 | 654 | */ |
655 | - public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
655 | + public function colourize(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
656 | 656 | { |
657 | 657 | return static::addColour($string, $foregroundColor, $backgroundColor, $bold); |
658 | 658 | } |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | */ |
664 | 664 | public function setLogLevel(string $level) : Logger |
665 | 665 | { |
666 | - if ( ! isset(static::$logLevels[$level]) ) |
|
666 | + if ( ! isset(static::$logLevels[ $level ])) |
|
667 | 667 | { |
668 | 668 | throw new \InvalidArgumentException("Log level is invalid"); |
669 | 669 | } |
670 | - $this->level = static::$logLevels[$level][0]; |
|
670 | + $this->level = static::$logLevels[ $level ][ 0 ]; |
|
671 | 671 | |
672 | 672 | return $this; |
673 | 673 | } |
@@ -711,25 +711,25 @@ discard block |
||
711 | 711 | * @param string|object $message If an object is passed it must implement __toString() |
712 | 712 | * @param array $context Placeholders to be substituted in the message |
713 | 713 | */ |
714 | - public function log($level, $message, array $context=[]) |
|
714 | + public function log($level, $message, array $context = [ ]) |
|
715 | 715 | { |
716 | - $level = isset(static::$logLevels[$level]) ? $level : self::INFO; |
|
717 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$level]; |
|
716 | + $level = isset(static::$logLevels[ $level ]) ? $level : self::INFO; |
|
717 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $level ]; |
|
718 | 718 | unset($style); |
719 | - if ( $logLevel > $this->level ) |
|
719 | + if ($logLevel > $this->level) |
|
720 | 720 | { |
721 | - return ; |
|
721 | + return; |
|
722 | 722 | } |
723 | - if ( is_callable($this->formatter) ) |
|
723 | + if (is_callable($this->formatter)) |
|
724 | 724 | { |
725 | - $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); |
|
725 | + $message = $this->formatter->__invoke(static::$logLevels[ $level ][ 4 ], $message, $context); |
|
726 | 726 | } |
727 | 727 | else |
728 | 728 | { |
729 | 729 | $message = $this->formatMessage($level, $message, $context); |
730 | 730 | } |
731 | 731 | $this->lastLogEntry = $message; |
732 | - $this->write($this->colourize($message, $fore, $back) . PHP_EOL); |
|
732 | + $this->write($this->colourize($message, $fore, $back).PHP_EOL); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
@@ -739,8 +739,8 @@ discard block |
||
739 | 739 | */ |
740 | 740 | public static function style(string $style, string $message) : string |
741 | 741 | { |
742 | - $style = isset(static::$logLevels[$style]) ? $style : self::INFO; |
|
743 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$style]; |
|
742 | + $style = isset(static::$logLevels[ $style ]) ? $style : self::INFO; |
|
743 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $style ]; |
|
744 | 744 | unset($logLevel, $style); |
745 | 745 | |
746 | 746 | return static::addColour($message, $fore, $back); |
@@ -752,14 +752,14 @@ discard block |
||
752 | 752 | * @param array $context |
753 | 753 | * @return string |
754 | 754 | */ |
755 | - protected function formatMessage(string $level, string $message, array $context=[]) : string |
|
755 | + protected function formatMessage(string $level, string $message, array $context = [ ]) : string |
|
756 | 756 | { |
757 | 757 | # Handle objects implementing __toString |
758 | - $message = (string) $message; |
|
759 | - $message .= empty($context) ? '' : PHP_EOL . json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
760 | - $data = $this->addDate ? ['date' => date('Y-m-d H:i:s')] : []; |
|
761 | - $data['level'] = strtoupper(str_pad(static::$logLevels[$level][4], 5, ' ', STR_PAD_RIGHT)); |
|
762 | - $data['message'] = $message; |
|
758 | + $message = (string)$message; |
|
759 | + $message .= empty($context) ? '' : PHP_EOL.json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
760 | + $data = $this->addDate ? [ 'date' => date('Y-m-d H:i:s') ] : [ ]; |
|
761 | + $data[ 'level' ] = strtoupper(str_pad(static::$logLevels[ $level ][ 4 ], 5, ' ', STR_PAD_RIGHT)); |
|
762 | + $data[ 'message' ] = $message; |
|
763 | 763 | |
764 | 764 | return implode($this->separator, $data); |
765 | 765 | } |
@@ -772,12 +772,12 @@ discard block |
||
772 | 772 | public function write(string $content) |
773 | 773 | { |
774 | 774 | $resource = $this->getResource(); |
775 | - if ( $this->useLocking ) |
|
775 | + if ($this->useLocking) |
|
776 | 776 | { |
777 | 777 | flock($resource, LOCK_EX); |
778 | 778 | } |
779 | 779 | gzwrite($resource, $content); |
780 | - if ( $this->useLocking ) |
|
780 | + if ($this->useLocking) |
|
781 | 781 | { |
782 | 782 | flock($resource, LOCK_UN); |
783 | 783 | } |
@@ -789,14 +789,14 @@ discard block |
||
789 | 789 | */ |
790 | 790 | protected function getResource() |
791 | 791 | { |
792 | - if ( is_resource($this->resource) ) |
|
792 | + if (is_resource($this->resource)) |
|
793 | 793 | { |
794 | 794 | return $this->resource; |
795 | 795 | } |
796 | 796 | $fileName = $this->resource; |
797 | 797 | $this->closeLocally = true; |
798 | 798 | $this->resource = $this->openResource(); |
799 | - if ( ! is_resource($this->resource) ) |
|
799 | + if ( ! is_resource($this->resource)) |
|
800 | 800 | { |
801 | 801 | throw new \Exception("The resource ({$fileName}) could not be opened"); |
802 | 802 | } |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | protected function openResource() |
819 | 819 | { |
820 | - if ( $this->gzipFile ) |
|
820 | + if ($this->gzipFile) |
|
821 | 821 | { |
822 | 822 | return gzopen($this->resource, 'a'); |
823 | 823 | } |
@@ -132,8 +132,7 @@ discard block |
||
132 | 132 | $this->getLogger()->info("[{$testName}] - Starting..."); |
133 | 133 | $testCase->runTest($this); |
134 | 134 | $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); |
135 | - } |
|
136 | - catch ( \Exception $e ) |
|
135 | + } catch ( \Exception $e ) |
|
137 | 136 | { |
138 | 137 | $expectedCode = $testCase->getExceptionCode(); |
139 | 138 | $expectedClass = $testCase->getExceptionType(); |
@@ -723,8 +722,7 @@ discard block |
||
723 | 722 | if ( is_callable($this->formatter) ) |
724 | 723 | { |
725 | 724 | $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); |
726 | - } |
|
727 | - else |
|
725 | + } else |
|
728 | 726 | { |
729 | 727 | $message = $this->formatMessage($level, $message, $context); |
730 | 728 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | #!/usr/bin/env php |
2 | -<?php declare(strict_types=1); |
|
2 | +<?php declare(strict_types = 1); |
|
3 | 3 | |
4 | 4 | use Terah\Assert\Tester; |
5 | 5 | |
6 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
6 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
7 | 7 | |
8 | 8 | class TestRunner |
9 | 9 | { |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | $test = (string)static::getArg('test', ''); |
15 | 15 | $recursive = (bool)static::getArg('recursive', true); |
16 | 16 | $tests = static::getTestFiles($fileName, $recursive); |
17 | - if ( empty($tests) ) |
|
17 | + if (empty($tests)) |
|
18 | 18 | { |
19 | 19 | Tester::getLogger()->error("No test files found/specified"); |
20 | 20 | |
21 | 21 | exit(1); |
22 | 22 | } |
23 | - foreach ( $tests as $fileName ) |
|
23 | + foreach ($tests as $fileName) |
|
24 | 24 | { |
25 | 25 | Tester::getLogger()->debug("Loading test file {$fileName}"); |
26 | 26 | require($fileName); |
@@ -35,46 +35,46 @@ discard block |
||
35 | 35 | * @param bool $recursive |
36 | 36 | * @return array |
37 | 37 | */ |
38 | - public static function getTestFiles(string $fileName='', bool $recursive=false) : array |
|
38 | + public static function getTestFiles(string $fileName = '', bool $recursive = false) : array |
|
39 | 39 | { |
40 | - if ( empty($fileName) ) |
|
40 | + if (empty($fileName)) |
|
41 | 41 | { |
42 | - return []; |
|
42 | + return [ ]; |
|
43 | 43 | } |
44 | - if ( ! file_exists($fileName) ) |
|
44 | + if ( ! file_exists($fileName)) |
|
45 | 45 | { |
46 | 46 | Tester::getLogger()->error("{$fileName} does not exist; exiting"); |
47 | 47 | |
48 | 48 | exit(1); |
49 | 49 | } |
50 | - $fileName = realpath($fileName); |
|
51 | - if ( is_dir($fileName) ) |
|
50 | + $fileName = realpath($fileName); |
|
51 | + if (is_dir($fileName)) |
|
52 | 52 | { |
53 | - $iterator = new \DirectoryIterator($fileName); |
|
54 | - if ( $recursive ) |
|
53 | + $iterator = new \DirectoryIterator($fileName); |
|
54 | + if ($recursive) |
|
55 | 55 | { |
56 | 56 | $iterator = new \RecursiveDirectoryIterator($fileName); |
57 | 57 | $iterator = $recursive ? new RecursiveIteratorIterator($iterator) : $iterator; |
58 | 58 | } |
59 | - $testFiles = []; |
|
60 | - foreach ( $iterator as $fileInfo ) |
|
59 | + $testFiles = [ ]; |
|
60 | + foreach ($iterator as $fileInfo) |
|
61 | 61 | { |
62 | - if ( preg_match('/Suite.php$/', $fileInfo->getBasename()) ) |
|
62 | + if (preg_match('/Suite.php$/', $fileInfo->getBasename())) |
|
63 | 63 | { |
64 | - $testFiles[] = $fileInfo->getPathname(); |
|
64 | + $testFiles[ ] = $fileInfo->getPathname(); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | return $testFiles; |
69 | 69 | } |
70 | - if ( ! is_file($fileName) ) |
|
70 | + if ( ! is_file($fileName)) |
|
71 | 71 | { |
72 | 72 | Tester::getLogger()->error("{$fileName} is not a file; exiting"); |
73 | 73 | |
74 | 74 | exit(1); |
75 | 75 | } |
76 | 76 | |
77 | - return [$fileName]; |
|
77 | + return [ $fileName ]; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $argv |
128 | 128 | * @return array |
129 | 129 | */ |
130 | - public static function parseArgs(array $argv=[]) : array |
|
130 | + public static function parseArgs(array $argv = [ ]) : array |
|
131 | 131 | { |
132 | - $argv = $argv ?: ! empty($_SERVER['argv']) ? $_SERVER['argv'] : []; |
|
132 | + $argv = $argv ?: ! empty($_SERVER[ 'argv' ]) ? $_SERVER[ 'argv' ] : [ ]; |
|
133 | 133 | array_shift($argv); |
134 | - $out = []; |
|
135 | - for ( $i = 0, $j = count($argv); $i < $j; $i++ ) |
|
134 | + $out = [ ]; |
|
135 | + for ($i = 0, $j = count($argv); $i < $j; $i++) |
|
136 | 136 | { |
137 | - $arg = $argv[$i]; |
|
137 | + $arg = $argv[ $i ]; |
|
138 | 138 | // --foo --bar=baz |
139 | - if ( mb_substr($arg, 0, 2) === '--' ) |
|
139 | + if (mb_substr($arg, 0, 2) === '--') |
|
140 | 140 | { |
141 | 141 | $eqPos = mb_strpos($arg, '='); |
142 | 142 | // --foo |
@@ -144,23 +144,23 @@ discard block |
||
144 | 144 | { |
145 | 145 | $key = mb_substr($arg, 2); |
146 | 146 | // --foo value |
147 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') |
|
147 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') |
|
148 | 148 | { |
149 | - $value = $argv[$i + 1]; |
|
149 | + $value = $argv[ $i + 1 ]; |
|
150 | 150 | $i++; |
151 | 151 | } |
152 | 152 | else |
153 | 153 | { |
154 | - $value = isset($out[$key]) ? $out[$key] : true; |
|
154 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; |
|
155 | 155 | } |
156 | - $out[$key] = $value; |
|
156 | + $out[ $key ] = $value; |
|
157 | 157 | } |
158 | 158 | // --bar=baz |
159 | 159 | else |
160 | 160 | { |
161 | 161 | $key = mb_substr($arg, 2, $eqPos - 2); |
162 | 162 | $value = mb_substr($arg, $eqPos + 1); |
163 | - $out[$key] = $value; |
|
163 | + $out[ $key ] = $value; |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | // -k=value -abc |
@@ -171,23 +171,23 @@ discard block |
||
171 | 171 | { |
172 | 172 | $key = mb_substr($arg, 1, 1); |
173 | 173 | $value = mb_substr($arg, 3); |
174 | - $out[$key] = $value; |
|
174 | + $out[ $key ] = $value; |
|
175 | 175 | } |
176 | 176 | // -abc |
177 | 177 | else |
178 | 178 | { |
179 | 179 | $chars = str_split(mb_substr($arg, 1)); |
180 | 180 | $key = ''; |
181 | - foreach ( $chars as $char ) |
|
181 | + foreach ($chars as $char) |
|
182 | 182 | { |
183 | 183 | $key = $char; |
184 | - $value = isset($out[$key]) ? $out[$key] : true; |
|
185 | - $out[$key] = $value; |
|
184 | + $value = isset($out[ $key ]) ? $out[ $key ] : true; |
|
185 | + $out[ $key ] = $value; |
|
186 | 186 | } |
187 | 187 | // -a value1 -abc value2 |
188 | - if ($i + 1 < $j && $argv[$i + 1][0] !== '-') |
|
188 | + if ($i + 1 < $j && $argv[ $i + 1 ][ 0 ] !== '-') |
|
189 | 189 | { |
190 | - $out[$key] = $argv[$i + 1]; |
|
190 | + $out[ $key ] = $argv[ $i + 1 ]; |
|
191 | 191 | $i++; |
192 | 192 | } |
193 | 193 | } |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | else |
197 | 197 | { |
198 | 198 | $value = $arg; |
199 | - $out[] = $value; |
|
199 | + $out[ ] = $value; |
|
200 | 200 | } |
201 | 201 | } |
202 | - foreach ( $out as $idx => $val ) |
|
202 | + foreach ($out as $idx => $val) |
|
203 | 203 | { |
204 | - if ( is_string($val) && strpos($val, '|') !== false ) |
|
204 | + if (is_string($val) && strpos($val, '|') !== false) |
|
205 | 205 | { |
206 | - $out[$idx] = explode('|', $val); |
|
206 | + $out[ $idx ] = explode('|', $val); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -215,11 +215,11 @@ discard block |
||
215 | 215 | * @param mixed $default |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - protected static function getArg($name, $default=null) |
|
218 | + protected static function getArg($name, $default = null) |
|
219 | 219 | { |
220 | 220 | $args = static::parseArgs(); |
221 | 221 | |
222 | - return isset($args[$name]) && $args[$name] ? $args[$name] : $default; |
|
222 | + return isset($args[ $name ]) && $args[ $name ] ? $args[ $name ] : $default; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -148,8 +148,7 @@ |
||
148 | 148 | { |
149 | 149 | $value = $argv[$i + 1]; |
150 | 150 | $i++; |
151 | - } |
|
152 | - else |
|
151 | + } else |
|
153 | 152 | { |
154 | 153 | $value = isset($out[$key]) ? $out[$key] : true; |
155 | 154 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | |
@@ -29,5 +29,5 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @var string |
31 | 31 | */ |
32 | - protected $exceptionClass = ValidationFailedException::class; |
|
32 | + protected $exceptionClass = ValidationFailedException::class; |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param array $constraints |
41 | 41 | * @param string $level |
42 | 42 | */ |
43 | - public function __construct(string $message, int $code, string $fieldName='', $value, array $constraints=[], string $level='critical', string $propertyPath='') |
|
43 | + public function __construct(string $message, int $code, string $fieldName = '', $value, array $constraints = [ ], string $level = 'critical', string $propertyPath = '') |
|
44 | 44 | { |
45 | 45 | parent::__construct($message, $code); |
46 | 46 | $this->fieldName = $fieldName; |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | $this->constraints = $constraints; |
49 | 49 | $this->level = $level; |
50 | 50 | $this->propertyPath = $propertyPath; |
51 | - foreach ( $this->getTrace() as $point ) |
|
51 | + foreach ($this->getTrace() as $point) |
|
52 | 52 | { |
53 | - if ( $this->location ) |
|
53 | + if ($this->location) |
|
54 | 54 | { |
55 | 55 | continue; |
56 | 56 | } |
57 | - $class = $point['class'] ??0?: ''; |
|
58 | - if ( $class !== Assert::class ) |
|
57 | + $class = $point[ 'class' ] ??0 ?: ''; |
|
58 | + if ($class !== Assert::class) |
|
59 | 59 | { |
60 | 60 | $this->location = (object)$point; |
61 | 61 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function getPropertyPathAndCallingLocation() : string |
125 | 125 | { |
126 | - return $this->getPropertyPath() . ' in ' . $this->getCallingFileAndLine(); |
|
126 | + return $this->getPropertyPath().' in '.$this->getCallingFileAndLine(); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function getCallingFileAndLine() : string |
136 | 136 | { |
137 | - foreach ( $this->getTrace() as $trace ) |
|
137 | + foreach ($this->getTrace() as $trace) |
|
138 | 138 | { |
139 | 139 | $trace = (object)$trace; |
140 | - if ( empty($trace->file) ) |
|
140 | + if (empty($trace->file)) |
|
141 | 141 | { |
142 | 142 | continue; |
143 | 143 | } |
144 | 144 | $file = static::beforeLast('.php', static::afterLast('/', $trace->file)); |
145 | - if ( in_array($file, ['AssertionChain', 'Assertion']) ) |
|
145 | + if (in_array($file, [ 'AssertionChain', 'Assertion' ])) |
|
146 | 146 | { |
147 | 147 | continue; |
148 | 148 | } |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @param bool $returnOriginal |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public static function afterLast(string $needle, string $haystack, bool $returnOriginal=false) : string |
|
172 | + public static function afterLast(string $needle, string $haystack, bool $returnOriginal = false) : string |
|
173 | 173 | { |
174 | - if ( static::strrevpos($haystack, $needle) !== -1 ) |
|
174 | + if (static::strrevpos($haystack, $needle) !== -1) |
|
175 | 175 | { |
176 | 176 | return mb_substr($haystack, static::strrevpos($haystack, $needle) + mb_strlen($needle)); |
177 | 177 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public static function beforeLast(string $needle, string $haystack) : string |
200 | 200 | { |
201 | - $position = static::strrevpos($haystack, $needle); |
|
201 | + $position = static::strrevpos($haystack, $needle); |
|
202 | 202 | |
203 | 203 | return $position === -1 ? '' : mb_substr($haystack, 0, static::strrevpos($haystack, $needle)); |
204 | 204 | } |