@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | - * @param $exceptionClass |
|
221 | + * @param string $exceptionClass |
|
222 | 222 | * @return Assert |
223 | 223 | */ |
224 | 224 | public function setExceptionClass($exceptionClass) |
@@ -1220,7 +1220,7 @@ discard block |
||
1220 | 1220 | * |
1221 | 1221 | * @throws AssertionFailedException |
1222 | 1222 | * |
1223 | - * @param array $choices |
|
1223 | + * @param integer[] $choices |
|
1224 | 1224 | * @param string|null $message |
1225 | 1225 | * @param string|null $propertyPath |
1226 | 1226 | * @return $this |
@@ -2352,7 +2352,7 @@ discard block |
||
2352 | 2352 | } |
2353 | 2353 | |
2354 | 2354 | /** |
2355 | - * @param $func |
|
2355 | + * @param string $func |
|
2356 | 2356 | * @param $args |
2357 | 2357 | * @return bool |
2358 | 2358 | * @throws AssertionFailedException |
@@ -1972,8 +1972,7 @@ discard block |
||
1972 | 1972 | $this->stringify($this->value) |
1973 | 1973 | ); |
1974 | 1974 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_EMAIL, $propertyPath); |
1975 | - } |
|
1976 | - else |
|
1975 | + } else |
|
1977 | 1976 | { |
1978 | 1977 | $host = substr($this->value, strpos($this->value, '@') + 1); |
1979 | 1978 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
@@ -2099,8 +2098,7 @@ discard block |
||
2099 | 2098 | try |
2100 | 2099 | { |
2101 | 2100 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); |
2102 | - } |
|
2103 | - catch (AssertionFailedException $e) |
|
2101 | + } catch (AssertionFailedException $e) |
|
2104 | 2102 | { |
2105 | 2103 | $message = $message ?: $this->overrideError; |
2106 | 2104 | $message = sprintf( |
@@ -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 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @var string |
130 | 130 | */ |
131 | - protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
131 | + protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @param mixed $value |
@@ -146,22 +146,22 @@ discard block |
||
146 | 146 | * @param string $level |
147 | 147 | * @return Assert |
148 | 148 | */ |
149 | - public static function that($value, $name='', $code=0, $error='', $level=Assert::WARNING) |
|
149 | + public static function that($value, $name = '', $code = 0, $error = '', $level = Assert::WARNING) |
|
150 | 150 | { |
151 | 151 | $assert = new static($value); |
152 | - if ( $name ) |
|
152 | + if ($name) |
|
153 | 153 | { |
154 | 154 | $assert->name($name); |
155 | 155 | } |
156 | - if ( $code ) |
|
156 | + if ($code) |
|
157 | 157 | { |
158 | 158 | $assert->code($code); |
159 | 159 | } |
160 | - if ( $error ) |
|
160 | + if ($error) |
|
161 | 161 | { |
162 | 162 | $assert->error($error); |
163 | 163 | } |
164 | - if ( $level ) |
|
164 | + if ($level) |
|
165 | 165 | { |
166 | 166 | $assert->level($level); |
167 | 167 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param string $level |
231 | 231 | * @return AssertionFailedException |
232 | 232 | */ |
233 | - protected function createException($message, $code, $propertyPath, array $constraints = [], $level=null) |
|
233 | + protected function createException($message, $code, $propertyPath, array $constraints = [ ], $level = null) |
|
234 | 234 | { |
235 | 235 | $exceptionClass = $this->exceptionClass; |
236 | 236 | $propertyPath = is_null($propertyPath) ? $this->propertyPath : $propertyPath; |
@@ -300,11 +300,11 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function eq($value2, $message = null, $propertyPath = null) |
302 | 302 | { |
303 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
303 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
304 | 304 | { |
305 | 305 | return $this; |
306 | 306 | } |
307 | - if ( $this->value != $value2 ) |
|
307 | + if ($this->value != $value2) |
|
308 | 308 | { |
309 | 309 | $message = $message ?: $this->overrideError; |
310 | 310 | $message = sprintf( |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $this->stringify($this->value), |
313 | 313 | $this->stringify($value2) |
314 | 314 | ); |
315 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
315 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
316 | 316 | } |
317 | 317 | return $this; |
318 | 318 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function greaterThan($value2, $message = null, $propertyPath = null) |
329 | 329 | { |
330 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
330 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
331 | 331 | { |
332 | 332 | return $this; |
333 | 333 | } |
334 | - if ( ! ( $this->value > $value2 ) ) |
|
334 | + if ( ! ($this->value > $value2)) |
|
335 | 335 | { |
336 | 336 | $message = $message ?: $this->overrideError; |
337 | 337 | $message = sprintf( |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | $this->stringify($this->value), |
340 | 340 | $this->stringify($value2) |
341 | 341 | ); |
342 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
342 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
343 | 343 | } |
344 | 344 | return $this; |
345 | 345 | } |
@@ -354,11 +354,11 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function greaterThanOrEq($value2, $message = null, $propertyPath = null) |
356 | 356 | { |
357 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
357 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
358 | 358 | { |
359 | 359 | return $this; |
360 | 360 | } |
361 | - if ( ! ( $this->value >= $value2 ) ) |
|
361 | + if ( ! ($this->value >= $value2)) |
|
362 | 362 | { |
363 | 363 | $message = $message ?: $this->overrideError; |
364 | 364 | $message = sprintf( |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $this->stringify($this->value), |
367 | 367 | $this->stringify($value2) |
368 | 368 | ); |
369 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
369 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
370 | 370 | } |
371 | 371 | return $this; |
372 | 372 | } |
@@ -381,11 +381,11 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function lessThan($value2, $message = null, $propertyPath = null) |
383 | 383 | { |
384 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
384 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
385 | 385 | { |
386 | 386 | return $this; |
387 | 387 | } |
388 | - if ( ! ( $this->value < $value2 ) ) |
|
388 | + if ( ! ($this->value < $value2)) |
|
389 | 389 | { |
390 | 390 | $message = $message ?: $this->overrideError; |
391 | 391 | $message = sprintf( |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $this->stringify($this->value), |
394 | 394 | $this->stringify($value2) |
395 | 395 | ); |
396 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]); |
|
396 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, [ 'expected' => $value2 ]); |
|
397 | 397 | } |
398 | 398 | return $this; |
399 | 399 | } |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | */ |
409 | 409 | public function lessThanOrEq($value2, $message = null, $propertyPath = null) |
410 | 410 | { |
411 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
411 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
412 | 412 | { |
413 | 413 | return $this; |
414 | 414 | } |
415 | - if ( ! ( $this->value <= $value2 ) ) |
|
415 | + if ( ! ($this->value <= $value2)) |
|
416 | 416 | { |
417 | 417 | $message = $message ?: $this->overrideError; |
418 | 418 | $message = sprintf( |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | $this->stringify($this->value), |
421 | 421 | $this->stringify($value2) |
422 | 422 | ); |
423 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]); |
|
423 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
424 | 424 | } |
425 | 425 | return $this; |
426 | 426 | } |
@@ -436,11 +436,11 @@ discard block |
||
436 | 436 | */ |
437 | 437 | public function same($value2, $message = null, $propertyPath = null) |
438 | 438 | { |
439 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
439 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
440 | 440 | { |
441 | 441 | return $this; |
442 | 442 | } |
443 | - if ( $this->value !== $value2 ) |
|
443 | + if ($this->value !== $value2) |
|
444 | 444 | { |
445 | 445 | $message = $message ?: $this->overrideError; |
446 | 446 | $message = sprintf( |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | $this->stringify($this->value), |
449 | 449 | $this->stringify($value2) |
450 | 450 | ); |
451 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, ['expected' => $value2]); |
|
451 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
452 | 452 | } |
453 | 453 | return $this; |
454 | 454 | } |
@@ -464,11 +464,11 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function notEq($value2, $message = null, $propertyPath = null) |
466 | 466 | { |
467 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
467 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
468 | 468 | { |
469 | 469 | return $this; |
470 | 470 | } |
471 | - if ( $this->value == $value2 ) |
|
471 | + if ($this->value == $value2) |
|
472 | 472 | { |
473 | 473 | $message = $message ?: $this->overrideError; |
474 | 474 | $message = sprintf( |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | $this->stringify($this->value), |
477 | 477 | $this->stringify($value2) |
478 | 478 | ); |
479 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, ['expected' => $value2]); |
|
479 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
480 | 480 | } |
481 | 481 | return $this; |
482 | 482 | } |
@@ -490,11 +490,11 @@ discard block |
||
490 | 490 | */ |
491 | 491 | public function isCallable($message = null, $propertyPath = null) |
492 | 492 | { |
493 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
493 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
494 | 494 | { |
495 | 495 | return $this; |
496 | 496 | } |
497 | - if ( !is_callable($this->value) ) |
|
497 | + if ( ! is_callable($this->value)) |
|
498 | 498 | { |
499 | 499 | $message = $message ?: $this->overrideError; |
500 | 500 | $message = sprintf( |
@@ -517,11 +517,11 @@ discard block |
||
517 | 517 | */ |
518 | 518 | public function notSame($value2, $message = null, $propertyPath = null) |
519 | 519 | { |
520 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
520 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
521 | 521 | { |
522 | 522 | return $this; |
523 | 523 | } |
524 | - if ( $this->value === $value2 ) |
|
524 | + if ($this->value === $value2) |
|
525 | 525 | { |
526 | 526 | $message = $message ?: $this->overrideError; |
527 | 527 | $message = sprintf( |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | $this->stringify($this->value), |
530 | 530 | $this->stringify($value2) |
531 | 531 | ); |
532 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, ['expected' => $value2]); |
|
532 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
533 | 533 | } |
534 | 534 | return $this; |
535 | 535 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return Assert |
554 | 554 | * @throws AssertionFailedException |
555 | 555 | */ |
556 | - public function unsignedInt($message=null, $propertyPath=null) |
|
556 | + public function unsignedInt($message = null, $propertyPath = null) |
|
557 | 557 | { |
558 | 558 | $message = $message ?: $this->overrideError; |
559 | 559 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | { |
585 | 585 | $message = $message ?: $this->overrideError; |
586 | 586 | $message = $message ?: 'Value "%s" is not a valid status.'; |
587 | - return $this->integer($message, $propertyPath)->inArray([-1, 0, 1]); |
|
587 | + return $this->integer($message, $propertyPath)->inArray([-1, 0, 1 ]); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -628,11 +628,11 @@ discard block |
||
628 | 628 | */ |
629 | 629 | public function integer($message = null, $propertyPath = null) |
630 | 630 | { |
631 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
631 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
632 | 632 | { |
633 | 633 | return $this; |
634 | 634 | } |
635 | - if ( !is_int($this->value) ) |
|
635 | + if ( ! is_int($this->value)) |
|
636 | 636 | { |
637 | 637 | $message = $message ?: $this->overrideError; |
638 | 638 | $message = sprintf( |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function float($message = null, $propertyPath = null) |
656 | 656 | { |
657 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
657 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
658 | 658 | { |
659 | 659 | return $this; |
660 | 660 | } |
661 | - if ( ! is_float($this->value) ) |
|
661 | + if ( ! is_float($this->value)) |
|
662 | 662 | { |
663 | 663 | $message = $message ?: $this->overrideError; |
664 | 664 | $message = sprintf( |
@@ -680,11 +680,11 @@ discard block |
||
680 | 680 | */ |
681 | 681 | public function digit($message = null, $propertyPath = null) |
682 | 682 | { |
683 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
683 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
684 | 684 | { |
685 | 685 | return $this; |
686 | 686 | } |
687 | - if ( ! ctype_digit((string)$this->value) ) |
|
687 | + if ( ! ctype_digit((string)$this->value)) |
|
688 | 688 | { |
689 | 689 | $message = $message ?: $this->overrideError; |
690 | 690 | $message = sprintf( |
@@ -706,12 +706,12 @@ discard block |
||
706 | 706 | */ |
707 | 707 | public function date($message = null, $propertyPath = null) |
708 | 708 | { |
709 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
709 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
710 | 710 | { |
711 | 711 | return $this; |
712 | 712 | } |
713 | 713 | $this->notEmpty($message, $propertyPath); |
714 | - if ( strtotime($this->value) === false ) |
|
714 | + if (strtotime($this->value) === false) |
|
715 | 715 | { |
716 | 716 | $message = $message ?: $this->overrideError; |
717 | 717 | $message = sprintf( |
@@ -733,11 +733,11 @@ discard block |
||
733 | 733 | */ |
734 | 734 | public function integerish($message = null, $propertyPath = null) |
735 | 735 | { |
736 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
736 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
737 | 737 | { |
738 | 738 | return $this; |
739 | 739 | } |
740 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
740 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
741 | 741 | { |
742 | 742 | $message = $message ?: $this->overrideError; |
743 | 743 | $message = sprintf( |
@@ -759,11 +759,11 @@ discard block |
||
759 | 759 | */ |
760 | 760 | public function boolean($message = null, $propertyPath = null) |
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_bool($this->value) ) |
|
766 | + if ( ! is_bool($this->value)) |
|
767 | 767 | { |
768 | 768 | $message = $message ?: $this->overrideError; |
769 | 769 | $message = sprintf( |
@@ -785,11 +785,11 @@ discard block |
||
785 | 785 | */ |
786 | 786 | public function scalar($message = null, $propertyPath = null) |
787 | 787 | { |
788 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
788 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
789 | 789 | { |
790 | 790 | return $this; |
791 | 791 | } |
792 | - if ( ! is_scalar($this->value) ) |
|
792 | + if ( ! is_scalar($this->value)) |
|
793 | 793 | { |
794 | 794 | $message = $message ?: $this->overrideError; |
795 | 795 | $message = sprintf( |
@@ -811,11 +811,11 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function notEmpty($message = null, $propertyPath = null) |
813 | 813 | { |
814 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
814 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
815 | 815 | { |
816 | 816 | return $this; |
817 | 817 | } |
818 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
818 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
819 | 819 | { |
820 | 820 | $message = $message ?: $this->overrideError; |
821 | 821 | $message = sprintf( |
@@ -837,11 +837,11 @@ discard block |
||
837 | 837 | */ |
838 | 838 | public function noContent($message = null, $propertyPath = null) |
839 | 839 | { |
840 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
840 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
841 | 841 | { |
842 | 842 | return $this; |
843 | 843 | } |
844 | - if ( !empty( $this->value ) ) |
|
844 | + if ( ! empty($this->value)) |
|
845 | 845 | { |
846 | 846 | $message = $message ?: $this->overrideError; |
847 | 847 | $message = sprintf( |
@@ -863,11 +863,11 @@ discard block |
||
863 | 863 | */ |
864 | 864 | public function notNull($message = null, $propertyPath = null) |
865 | 865 | { |
866 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
866 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
867 | 867 | { |
868 | 868 | return $this; |
869 | 869 | } |
870 | - if ( $this->value === null ) |
|
870 | + if ($this->value === null) |
|
871 | 871 | { |
872 | 872 | $message = $message ?: $this->overrideError; |
873 | 873 | $message = sprintf( |
@@ -889,11 +889,11 @@ discard block |
||
889 | 889 | */ |
890 | 890 | public function string($message = null, $propertyPath = null) |
891 | 891 | { |
892 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
892 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
893 | 893 | { |
894 | 894 | return $this; |
895 | 895 | } |
896 | - if ( !is_string($this->value) ) |
|
896 | + if ( ! is_string($this->value)) |
|
897 | 897 | { |
898 | 898 | $message = $message ?: $this->overrideError; |
899 | 899 | $message = sprintf( |
@@ -915,21 +915,21 @@ discard block |
||
915 | 915 | * @return Assert |
916 | 916 | * @throws AssertionFailedException |
917 | 917 | */ |
918 | - public function regex($pattern, $message=null, $propertyPath=null) |
|
918 | + public function regex($pattern, $message = null, $propertyPath = null) |
|
919 | 919 | { |
920 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
920 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
921 | 921 | { |
922 | 922 | return $this; |
923 | 923 | } |
924 | 924 | $this->string($message, $propertyPath); |
925 | - if ( ! preg_match($pattern, $this->value) ) |
|
925 | + if ( ! preg_match($pattern, $this->value)) |
|
926 | 926 | { |
927 | 927 | $message = $message ?: $this->overrideError; |
928 | 928 | $message = sprintf( |
929 | 929 | $message ?: 'Value "%s" does not match expression.', |
930 | 930 | $this->stringify($this->value) |
931 | 931 | ); |
932 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
932 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
933 | 933 | } |
934 | 934 | return $this; |
935 | 935 | } |
@@ -942,13 +942,13 @@ discard block |
||
942 | 942 | */ |
943 | 943 | public function ipAddress($message = null, $propertyPath = null) |
944 | 944 | { |
945 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
945 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
946 | 946 | { |
947 | 947 | return $this; |
948 | 948 | } |
949 | 949 | $this->string($message, $propertyPath); |
950 | - $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])$/'; |
|
951 | - if ( ! preg_match($pattern, $this->value) ) |
|
950 | + $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])$/'; |
|
951 | + if ( ! preg_match($pattern, $this->value)) |
|
952 | 952 | { |
953 | 953 | $message = $message ?: $this->overrideError; |
954 | 954 | $message = sprintf( |
@@ -969,19 +969,19 @@ discard block |
||
969 | 969 | */ |
970 | 970 | public function notRegex($pattern, $message = null, $propertyPath = null) |
971 | 971 | { |
972 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
972 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
973 | 973 | { |
974 | 974 | return $this; |
975 | 975 | } |
976 | 976 | $this->string($message, $propertyPath); |
977 | - if ( preg_match($pattern, $this->value) ) |
|
977 | + if (preg_match($pattern, $this->value)) |
|
978 | 978 | { |
979 | 979 | $message = $message ?: $this->overrideError; |
980 | 980 | $message = sprintf( |
981 | 981 | $message ?: 'Value "%s" does not match expression.', |
982 | 982 | $this->stringify($this->value) |
983 | 983 | ); |
984 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
984 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
985 | 985 | } |
986 | 986 | return $this; |
987 | 987 | } |
@@ -998,12 +998,12 @@ discard block |
||
998 | 998 | */ |
999 | 999 | public function length($length, $message = null, $propertyPath = null, $encoding = 'utf8') |
1000 | 1000 | { |
1001 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1001 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1002 | 1002 | { |
1003 | 1003 | return $this; |
1004 | 1004 | } |
1005 | 1005 | $this->string($message, $propertyPath); |
1006 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
1006 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
1007 | 1007 | { |
1008 | 1008 | $message = $message ?: $this->overrideError; |
1009 | 1009 | $message = sprintf( |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | $length, |
1013 | 1013 | mb_strlen($this->value, $encoding) |
1014 | 1014 | ); |
1015 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
1015 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
1016 | 1016 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $propertyPath, $constraints); |
1017 | 1017 | } |
1018 | 1018 | return $this; |
@@ -1030,22 +1030,22 @@ discard block |
||
1030 | 1030 | */ |
1031 | 1031 | public function minLength($minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1032 | 1032 | { |
1033 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1033 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1034 | 1034 | { |
1035 | 1035 | return $this; |
1036 | 1036 | } |
1037 | 1037 | $this->string($message, $propertyPath); |
1038 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1038 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1039 | 1039 | { |
1040 | 1040 | $message = $message ?: $this->overrideError; |
1041 | - $message = sprintf( |
|
1041 | + $message = sprintf( |
|
1042 | 1042 | $message |
1043 | 1043 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1044 | 1044 | $this->stringify($this->value), |
1045 | 1045 | $minLength, |
1046 | 1046 | mb_strlen($this->value, $encoding) |
1047 | 1047 | ); |
1048 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1048 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1049 | 1049 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
1050 | 1050 | } |
1051 | 1051 | return $this; |
@@ -1063,21 +1063,21 @@ discard block |
||
1063 | 1063 | */ |
1064 | 1064 | public function maxLength($maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1065 | 1065 | { |
1066 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1066 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1067 | 1067 | { |
1068 | 1068 | return $this; |
1069 | 1069 | } |
1070 | 1070 | $this->string($message, $propertyPath); |
1071 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1071 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1072 | 1072 | { |
1073 | 1073 | $message = $message ?: $this->overrideError; |
1074 | - $message = sprintf( |
|
1074 | + $message = sprintf( |
|
1075 | 1075 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1076 | 1076 | $this->stringify($this->value), |
1077 | 1077 | $maxLength, |
1078 | 1078 | mb_strlen($this->value, $encoding) |
1079 | 1079 | ); |
1080 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1080 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1081 | 1081 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1082 | 1082 | } |
1083 | 1083 | return $this; |
@@ -1096,34 +1096,34 @@ discard block |
||
1096 | 1096 | */ |
1097 | 1097 | public function betweenLength($minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1098 | 1098 | { |
1099 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1099 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1100 | 1100 | { |
1101 | 1101 | return $this; |
1102 | 1102 | } |
1103 | 1103 | $this->string($message, $propertyPath); |
1104 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1104 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1105 | 1105 | { |
1106 | 1106 | $message = $message ?: $this->overrideError; |
1107 | - $message = sprintf( |
|
1107 | + $message = sprintf( |
|
1108 | 1108 | $message |
1109 | 1109 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1110 | 1110 | $this->stringify($this->value), |
1111 | 1111 | $minLength, |
1112 | 1112 | mb_strlen($this->value, $encoding) |
1113 | 1113 | ); |
1114 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1114 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1115 | 1115 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
1116 | 1116 | } |
1117 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1117 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1118 | 1118 | { |
1119 | 1119 | $message = $message ?: $this->overrideError; |
1120 | - $message = sprintf( |
|
1120 | + $message = sprintf( |
|
1121 | 1121 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1122 | 1122 | $this->stringify($this->value), |
1123 | 1123 | $maxLength, |
1124 | 1124 | mb_strlen($this->value, $encoding) |
1125 | 1125 | ); |
1126 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1126 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1127 | 1127 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1128 | 1128 | } |
1129 | 1129 | return $this; |
@@ -1141,20 +1141,20 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1143 | 1143 | { |
1144 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1144 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1145 | 1145 | { |
1146 | 1146 | return $this; |
1147 | 1147 | } |
1148 | 1148 | $this->string($message, $propertyPath); |
1149 | - if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1149 | + if (mb_strpos($this->value, $needle, null, $encoding) !== 0) |
|
1150 | 1150 | { |
1151 | 1151 | $message = $message ?: $this->overrideError; |
1152 | - $message = sprintf( |
|
1152 | + $message = sprintf( |
|
1153 | 1153 | $message ?: 'Value "%s" does not start with "%s".', |
1154 | 1154 | $this->stringify($this->value), |
1155 | 1155 | $this->stringify($needle) |
1156 | 1156 | ); |
1157 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1157 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1158 | 1158 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
1159 | 1159 | } |
1160 | 1160 | return $this; |
@@ -1172,21 +1172,21 @@ discard block |
||
1172 | 1172 | */ |
1173 | 1173 | public function endsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1174 | 1174 | { |
1175 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1175 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1176 | 1176 | { |
1177 | 1177 | return $this; |
1178 | 1178 | } |
1179 | 1179 | $this->string($message, $propertyPath); |
1180 | 1180 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
1181 | - if ( mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition ) |
|
1181 | + if (mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition) |
|
1182 | 1182 | { |
1183 | 1183 | $message = $message ?: $this->overrideError; |
1184 | - $message = sprintf( |
|
1184 | + $message = sprintf( |
|
1185 | 1185 | $message ?: 'Value "%s" does not end with "%s".', |
1186 | 1186 | $this->stringify($this->value), |
1187 | 1187 | $this->stringify($needle) |
1188 | 1188 | ); |
1189 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1189 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1190 | 1190 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $propertyPath, $constraints); |
1191 | 1191 | } |
1192 | 1192 | return $this; |
@@ -1204,20 +1204,20 @@ discard block |
||
1204 | 1204 | */ |
1205 | 1205 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
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, $propertyPath); |
1212 | - if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1212 | + if (mb_strpos($this->value, $needle, null, $encoding) === false) |
|
1213 | 1213 | { |
1214 | 1214 | $message = $message ?: $this->overrideError; |
1215 | - $message = sprintf( |
|
1215 | + $message = sprintf( |
|
1216 | 1216 | $message ?: 'Value "%s" does not contain "%s".', |
1217 | 1217 | $this->stringify($this->value), |
1218 | 1218 | $this->stringify($needle) |
1219 | 1219 | ); |
1220 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1220 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1221 | 1221 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
1222 | 1222 | } |
1223 | 1223 | return $this; |
@@ -1234,11 +1234,11 @@ discard block |
||
1234 | 1234 | */ |
1235 | 1235 | public function choice(array $choices, $message = null, $propertyPath = null) |
1236 | 1236 | { |
1237 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1237 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1238 | 1238 | { |
1239 | 1239 | return $this; |
1240 | 1240 | } |
1241 | - if ( !in_array($this->value, $choices, true) ) |
|
1241 | + if ( ! in_array($this->value, $choices, true)) |
|
1242 | 1242 | { |
1243 | 1243 | $message = $message ?: $this->overrideError; |
1244 | 1244 | $message = sprintf( |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | $this->stringify($this->value), |
1247 | 1247 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
1248 | 1248 | ); |
1249 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, ['choices' => $choices]); |
|
1249 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, [ 'choices' => $choices ]); |
|
1250 | 1250 | } |
1251 | 1251 | return $this; |
1252 | 1252 | } |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | */ |
1264 | 1264 | public function inArray(array $choices, $message = null, $propertyPath = null) |
1265 | 1265 | { |
1266 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1266 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1267 | 1267 | { |
1268 | 1268 | return $this; |
1269 | 1269 | } |
@@ -1281,11 +1281,11 @@ discard block |
||
1281 | 1281 | */ |
1282 | 1282 | public function numeric($message = null, $propertyPath = null) |
1283 | 1283 | { |
1284 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1284 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1285 | 1285 | { |
1286 | 1286 | return $this; |
1287 | 1287 | } |
1288 | - if ( ! is_numeric($this->value) ) |
|
1288 | + if ( ! is_numeric($this->value)) |
|
1289 | 1289 | { |
1290 | 1290 | $message = $message ?: $this->overrideError; |
1291 | 1291 | $message = sprintf( |
@@ -1343,11 +1343,11 @@ discard block |
||
1343 | 1343 | */ |
1344 | 1344 | public function isArray($message = null, $propertyPath = null) |
1345 | 1345 | { |
1346 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1346 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1347 | 1347 | { |
1348 | 1348 | return $this; |
1349 | 1349 | } |
1350 | - if ( !is_array($this->value) ) |
|
1350 | + if ( ! is_array($this->value)) |
|
1351 | 1351 | { |
1352 | 1352 | $message = $message ?: $this->overrideError; |
1353 | 1353 | $message = sprintf( |
@@ -1369,11 +1369,11 @@ discard block |
||
1369 | 1369 | */ |
1370 | 1370 | public function isTraversable($message = null, $propertyPath = null) |
1371 | 1371 | { |
1372 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1372 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1373 | 1373 | { |
1374 | 1374 | return $this; |
1375 | 1375 | } |
1376 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
1376 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
1377 | 1377 | { |
1378 | 1378 | $message = $message ?: $this->overrideError; |
1379 | 1379 | $message = sprintf( |
@@ -1395,11 +1395,11 @@ discard block |
||
1395 | 1395 | */ |
1396 | 1396 | public function isArrayAccessible($message = null, $propertyPath = null) |
1397 | 1397 | { |
1398 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1398 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1399 | 1399 | { |
1400 | 1400 | return $this; |
1401 | 1401 | } |
1402 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
1402 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
1403 | 1403 | { |
1404 | 1404 | $message = $message ?: $this->overrideError; |
1405 | 1405 | $message = sprintf( |
@@ -1422,19 +1422,19 @@ discard block |
||
1422 | 1422 | */ |
1423 | 1423 | public function keyExists($key, $message = null, $propertyPath = null) |
1424 | 1424 | { |
1425 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1425 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1426 | 1426 | { |
1427 | 1427 | return $this; |
1428 | 1428 | } |
1429 | 1429 | $this->isArray($message, $propertyPath); |
1430 | - if ( !array_key_exists($key, $this->value) ) |
|
1430 | + if ( ! array_key_exists($key, $this->value)) |
|
1431 | 1431 | { |
1432 | 1432 | $message = $message ?: $this->overrideError; |
1433 | 1433 | $message = sprintf( |
1434 | 1434 | $message ?: 'Array does not contain an element with key "%s"', |
1435 | 1435 | $this->stringify($key) |
1436 | 1436 | ); |
1437 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, ['key' => $key]); |
|
1437 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1438 | 1438 | } |
1439 | 1439 | return $this; |
1440 | 1440 | } |
@@ -1450,21 +1450,21 @@ discard block |
||
1450 | 1450 | */ |
1451 | 1451 | public function keysExist($keys, $message = null, $propertyPath = null) |
1452 | 1452 | { |
1453 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1453 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1454 | 1454 | { |
1455 | 1455 | return $this; |
1456 | 1456 | } |
1457 | 1457 | $this->isArray($message, $propertyPath); |
1458 | - foreach ( $keys as $key ) |
|
1458 | + foreach ($keys as $key) |
|
1459 | 1459 | { |
1460 | - if ( !array_key_exists($key, $this->value) ) |
|
1460 | + if ( ! array_key_exists($key, $this->value)) |
|
1461 | 1461 | { |
1462 | 1462 | $message = $message |
1463 | 1463 | ?: sprintf( |
1464 | 1464 | 'Array does not contain an element with key "%s"', |
1465 | 1465 | $this->stringify($key) |
1466 | 1466 | ); |
1467 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, ['key' => $key]); |
|
1467 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | return $this; |
@@ -1481,19 +1481,19 @@ discard block |
||
1481 | 1481 | */ |
1482 | 1482 | public function propertyExists($key, $message = null, $propertyPath = null) |
1483 | 1483 | { |
1484 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1484 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1485 | 1485 | { |
1486 | 1486 | return $this; |
1487 | 1487 | } |
1488 | 1488 | $this->isObject($message, $propertyPath); |
1489 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1489 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1490 | 1490 | { |
1491 | 1491 | $message = $message |
1492 | 1492 | ?: sprintf( |
1493 | 1493 | 'Object does not contain a property with key "%s"', |
1494 | 1494 | $this->stringify($key) |
1495 | 1495 | ); |
1496 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, ['key' => $key]); |
|
1496 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1497 | 1497 | } |
1498 | 1498 | return $this; |
1499 | 1499 | } |
@@ -1509,22 +1509,22 @@ discard block |
||
1509 | 1509 | */ |
1510 | 1510 | public function propertiesExist(array $keys, $message = null, $propertyPath = null) |
1511 | 1511 | { |
1512 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1512 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1513 | 1513 | { |
1514 | 1514 | return $this; |
1515 | 1515 | } |
1516 | 1516 | $this->isObject($message, $propertyPath); |
1517 | - foreach ( $keys as $key ) |
|
1517 | + foreach ($keys as $key) |
|
1518 | 1518 | { |
1519 | 1519 | // Using isset to allow resolution of magically defined properties |
1520 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1520 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1521 | 1521 | { |
1522 | 1522 | $message = $message |
1523 | 1523 | ?: sprintf( |
1524 | 1524 | 'Object does not contain a property with key "%s"', |
1525 | 1525 | $this->stringify($key) |
1526 | 1526 | ); |
1527 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, ['key' => $key]); |
|
1527 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1528 | 1528 | } |
1529 | 1529 | } |
1530 | 1530 | return $this; |
@@ -1540,12 +1540,12 @@ discard block |
||
1540 | 1540 | */ |
1541 | 1541 | public function utf8($message = null, $propertyPath = null) |
1542 | 1542 | { |
1543 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1543 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1544 | 1544 | { |
1545 | 1545 | return $this; |
1546 | 1546 | } |
1547 | 1547 | $this->string($message, $propertyPath); |
1548 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1548 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
1549 | 1549 | { |
1550 | 1550 | $message = $message |
1551 | 1551 | ?: sprintf( |
@@ -1568,12 +1568,12 @@ discard block |
||
1568 | 1568 | */ |
1569 | 1569 | public function ascii($message = null, $propertyPath = null) |
1570 | 1570 | { |
1571 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1571 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1572 | 1572 | { |
1573 | 1573 | return $this; |
1574 | 1574 | } |
1575 | 1575 | $this->string($message, $propertyPath); |
1576 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1576 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
1577 | 1577 | { |
1578 | 1578 | $message = $message |
1579 | 1579 | ?: sprintf( |
@@ -1596,19 +1596,19 @@ discard block |
||
1596 | 1596 | */ |
1597 | 1597 | public function keyIsset($key, $message = null, $propertyPath = null) |
1598 | 1598 | { |
1599 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1599 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1600 | 1600 | { |
1601 | 1601 | return $this; |
1602 | 1602 | } |
1603 | 1603 | $this->isArrayAccessible($message, $propertyPath); |
1604 | - if ( !isset( $this->value[$key] ) ) |
|
1604 | + if ( ! isset($this->value[ $key ])) |
|
1605 | 1605 | { |
1606 | 1606 | $message = $message ?: $this->overrideError; |
1607 | 1607 | $message = sprintf( |
1608 | 1608 | $message ?: 'The element with key "%s" was not found', |
1609 | 1609 | $this->stringify($key) |
1610 | 1610 | ); |
1611 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, ['key' => $key]); |
|
1611 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, [ 'key' => $key ]); |
|
1612 | 1612 | } |
1613 | 1613 | return $this; |
1614 | 1614 | } |
@@ -1624,12 +1624,12 @@ discard block |
||
1624 | 1624 | */ |
1625 | 1625 | public function notEmptyKey($key, $message = null, $propertyPath = null) |
1626 | 1626 | { |
1627 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1627 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1628 | 1628 | { |
1629 | 1629 | return $this; |
1630 | 1630 | } |
1631 | 1631 | $this->keyIsset($key, $message, $propertyPath); |
1632 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1632 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1633 | 1633 | return $this; |
1634 | 1634 | } |
1635 | 1635 | |
@@ -1643,11 +1643,11 @@ discard block |
||
1643 | 1643 | */ |
1644 | 1644 | public function notBlank($message = null, $propertyPath = null) |
1645 | 1645 | { |
1646 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1646 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1647 | 1647 | { |
1648 | 1648 | return $this; |
1649 | 1649 | } |
1650 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
1650 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
1651 | 1651 | { |
1652 | 1652 | $message = $message ?: $this->overrideError; |
1653 | 1653 | $message = sprintf( |
@@ -1670,11 +1670,11 @@ discard block |
||
1670 | 1670 | */ |
1671 | 1671 | public function isInstanceOf($className, $message = null, $propertyPath = null) |
1672 | 1672 | { |
1673 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1673 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1674 | 1674 | { |
1675 | 1675 | return $this; |
1676 | 1676 | } |
1677 | - if ( !( $this->value instanceof $className ) ) |
|
1677 | + if ( ! ($this->value instanceof $className)) |
|
1678 | 1678 | { |
1679 | 1679 | $message = $message ?: $this->overrideError; |
1680 | 1680 | $message = sprintf( |
@@ -1682,7 +1682,7 @@ discard block |
||
1682 | 1682 | $this->stringify($this->value), |
1683 | 1683 | $className |
1684 | 1684 | ); |
1685 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1685 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1686 | 1686 | } |
1687 | 1687 | return $this; |
1688 | 1688 | } |
@@ -1698,11 +1698,11 @@ discard block |
||
1698 | 1698 | */ |
1699 | 1699 | public function notIsInstanceOf($className, $message = null, $propertyPath = null) |
1700 | 1700 | { |
1701 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1701 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1702 | 1702 | { |
1703 | 1703 | return $this; |
1704 | 1704 | } |
1705 | - if ( $this->value instanceof $className ) |
|
1705 | + if ($this->value instanceof $className) |
|
1706 | 1706 | { |
1707 | 1707 | $message = $message ?: $this->overrideError; |
1708 | 1708 | $message = sprintf( |
@@ -1710,7 +1710,7 @@ discard block |
||
1710 | 1710 | $this->stringify($this->value), |
1711 | 1711 | $className |
1712 | 1712 | ); |
1713 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1713 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1714 | 1714 | } |
1715 | 1715 | return $this; |
1716 | 1716 | } |
@@ -1726,11 +1726,11 @@ discard block |
||
1726 | 1726 | */ |
1727 | 1727 | public function subclassOf($className, $message = null, $propertyPath = null) |
1728 | 1728 | { |
1729 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1729 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1730 | 1730 | { |
1731 | 1731 | return $this; |
1732 | 1732 | } |
1733 | - if ( !is_subclass_of($this->value, $className) ) |
|
1733 | + if ( ! is_subclass_of($this->value, $className)) |
|
1734 | 1734 | { |
1735 | 1735 | $message = $message ?: $this->overrideError; |
1736 | 1736 | $message = sprintf( |
@@ -1738,7 +1738,7 @@ discard block |
||
1738 | 1738 | $this->stringify($this->value), |
1739 | 1739 | $className |
1740 | 1740 | ); |
1741 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, ['class' => $className]); |
|
1741 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, [ 'class' => $className ]); |
|
1742 | 1742 | } |
1743 | 1743 | return $this; |
1744 | 1744 | } |
@@ -1755,12 +1755,12 @@ discard block |
||
1755 | 1755 | */ |
1756 | 1756 | public function range($minValue, $maxValue, $message = null, $propertyPath = null) |
1757 | 1757 | { |
1758 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1758 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1759 | 1759 | { |
1760 | 1760 | return $this; |
1761 | 1761 | } |
1762 | 1762 | $this->numeric($message, $propertyPath); |
1763 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
1763 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
1764 | 1764 | { |
1765 | 1765 | $message = $message ?: $this->overrideError; |
1766 | 1766 | $message = sprintf( |
@@ -1788,12 +1788,12 @@ discard block |
||
1788 | 1788 | */ |
1789 | 1789 | public function min($minValue, $message = null, $propertyPath = null) |
1790 | 1790 | { |
1791 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1791 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1792 | 1792 | { |
1793 | 1793 | return $this; |
1794 | 1794 | } |
1795 | 1795 | $this->numeric($message, $propertyPath); |
1796 | - if ( $this->value < $minValue ) |
|
1796 | + if ($this->value < $minValue) |
|
1797 | 1797 | { |
1798 | 1798 | $message = $message ?: $this->overrideError; |
1799 | 1799 | $message = sprintf( |
@@ -1801,7 +1801,7 @@ discard block |
||
1801 | 1801 | $this->stringify($this->value), |
1802 | 1802 | $this->stringify($minValue) |
1803 | 1803 | ); |
1804 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, ['min' => $minValue]); |
|
1804 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, [ 'min' => $minValue ]); |
|
1805 | 1805 | } |
1806 | 1806 | return $this; |
1807 | 1807 | } |
@@ -1817,12 +1817,12 @@ discard block |
||
1817 | 1817 | */ |
1818 | 1818 | public function max($maxValue, $message = null, $propertyPath = null) |
1819 | 1819 | { |
1820 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1820 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1821 | 1821 | { |
1822 | 1822 | return $this; |
1823 | 1823 | } |
1824 | 1824 | $this->numeric($message, $propertyPath); |
1825 | - if ( $this->value > $maxValue ) |
|
1825 | + if ($this->value > $maxValue) |
|
1826 | 1826 | { |
1827 | 1827 | $message = $message ?: $this->overrideError; |
1828 | 1828 | $message = sprintf( |
@@ -1830,7 +1830,7 @@ discard block |
||
1830 | 1830 | $this->stringify($this->value), |
1831 | 1831 | $this->stringify($maxValue) |
1832 | 1832 | ); |
1833 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, ['max' => $maxValue]); |
|
1833 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, [ 'max' => $maxValue ]); |
|
1834 | 1834 | } |
1835 | 1835 | return $this; |
1836 | 1836 | } |
@@ -1845,13 +1845,13 @@ discard block |
||
1845 | 1845 | */ |
1846 | 1846 | public function file($message = null, $propertyPath = null) |
1847 | 1847 | { |
1848 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1848 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1849 | 1849 | { |
1850 | 1850 | return $this; |
1851 | 1851 | } |
1852 | 1852 | $this->string($message, $propertyPath); |
1853 | 1853 | $this->notEmpty($message, $propertyPath); |
1854 | - if ( !is_file($this->value) ) |
|
1854 | + if ( ! is_file($this->value)) |
|
1855 | 1855 | { |
1856 | 1856 | $message = $message ?: $this->overrideError; |
1857 | 1857 | $message = sprintf( |
@@ -1871,13 +1871,13 @@ discard block |
||
1871 | 1871 | */ |
1872 | 1872 | public function fileExists($message = null, $propertyPath = null) |
1873 | 1873 | { |
1874 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1874 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1875 | 1875 | { |
1876 | 1876 | return $this; |
1877 | 1877 | } |
1878 | 1878 | $this->string($message, $propertyPath); |
1879 | 1879 | $this->notEmpty($message, $propertyPath); |
1880 | - if ( ! file_exists($this->value) ) |
|
1880 | + if ( ! file_exists($this->value)) |
|
1881 | 1881 | { |
1882 | 1882 | $message = $message ?: $this->overrideError; |
1883 | 1883 | $message = sprintf( |
@@ -1899,12 +1899,12 @@ discard block |
||
1899 | 1899 | */ |
1900 | 1900 | public function directory($message = null, $propertyPath = null) |
1901 | 1901 | { |
1902 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1902 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1903 | 1903 | { |
1904 | 1904 | return $this; |
1905 | 1905 | } |
1906 | 1906 | $this->string($message, $propertyPath); |
1907 | - if ( !is_dir($this->value) ) |
|
1907 | + if ( ! is_dir($this->value)) |
|
1908 | 1908 | { |
1909 | 1909 | $message = $message ?: $this->overrideError; |
1910 | 1910 | $message = sprintf( |
@@ -1926,12 +1926,12 @@ discard block |
||
1926 | 1926 | */ |
1927 | 1927 | public function readable($message = null, $propertyPath = null) |
1928 | 1928 | { |
1929 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1929 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1930 | 1930 | { |
1931 | 1931 | return $this; |
1932 | 1932 | } |
1933 | 1933 | $this->string($message, $propertyPath); |
1934 | - if ( !is_readable($this->value) ) |
|
1934 | + if ( ! is_readable($this->value)) |
|
1935 | 1935 | { |
1936 | 1936 | $message = $message ?: $this->overrideError; |
1937 | 1937 | $message = sprintf( |
@@ -1953,12 +1953,12 @@ discard block |
||
1953 | 1953 | */ |
1954 | 1954 | public function writeable($message = null, $propertyPath = null) |
1955 | 1955 | { |
1956 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1956 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1957 | 1957 | { |
1958 | 1958 | return $this; |
1959 | 1959 | } |
1960 | 1960 | $this->string($message, $propertyPath); |
1961 | - if ( !is_writeable($this->value) ) |
|
1961 | + if ( ! is_writeable($this->value)) |
|
1962 | 1962 | { |
1963 | 1963 | $message = $message ?: $this->overrideError; |
1964 | 1964 | $message = sprintf( |
@@ -1981,12 +1981,12 @@ discard block |
||
1981 | 1981 | */ |
1982 | 1982 | public function email($message = null, $propertyPath = null) |
1983 | 1983 | { |
1984 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1984 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1985 | 1985 | { |
1986 | 1986 | return $this; |
1987 | 1987 | } |
1988 | 1988 | $this->string($message, $propertyPath); |
1989 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
1989 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
1990 | 1990 | { |
1991 | 1991 | $message = $message ?: $this->overrideError; |
1992 | 1992 | $message = sprintf( |
@@ -1999,7 +1999,7 @@ discard block |
||
1999 | 1999 | { |
2000 | 2000 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2001 | 2001 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
2002 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
2002 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
2003 | 2003 | { |
2004 | 2004 | $message = $message ?: $this->overrideError; |
2005 | 2005 | $message = sprintf( |
@@ -2020,7 +2020,7 @@ discard block |
||
2020 | 2020 | */ |
2021 | 2021 | public function emailPrefix($message = null, $propertyPath = null) |
2022 | 2022 | { |
2023 | - $this->value($this->value . '@example.com'); |
|
2023 | + $this->value($this->value.'@example.com'); |
|
2024 | 2024 | return $this->email($message, $propertyPath); |
2025 | 2025 | } |
2026 | 2026 | |
@@ -2040,12 +2040,12 @@ discard block |
||
2040 | 2040 | */ |
2041 | 2041 | public function url($message = null, $propertyPath = null) |
2042 | 2042 | { |
2043 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2043 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2044 | 2044 | { |
2045 | 2045 | return $this; |
2046 | 2046 | } |
2047 | 2047 | $this->string($message, $propertyPath); |
2048 | - $protocols = ['http', 'https']; |
|
2048 | + $protocols = [ 'http', 'https' ]; |
|
2049 | 2049 | $pattern = '~^ |
2050 | 2050 | (%s):// # protocol |
2051 | 2051 | ( |
@@ -2060,8 +2060,8 @@ discard block |
||
2060 | 2060 | (:[0-9]+)? # a port (optional) |
2061 | 2061 | (/?|/\S+) # a /, nothing or a / with something |
2062 | 2062 | $~ixu'; |
2063 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2064 | - if ( !preg_match($pattern, $this->value) ) |
|
2063 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2064 | + if ( ! preg_match($pattern, $this->value)) |
|
2065 | 2065 | { |
2066 | 2066 | $message = $message ?: $this->overrideError; |
2067 | 2067 | $message = sprintf( |
@@ -2086,13 +2086,13 @@ discard block |
||
2086 | 2086 | */ |
2087 | 2087 | public function domainName($message = null, $propertyPath = null) |
2088 | 2088 | { |
2089 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2089 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2090 | 2090 | { |
2091 | 2091 | return $this; |
2092 | 2092 | } |
2093 | 2093 | $this->string($message, $propertyPath); |
2094 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2095 | - if ( ! preg_match($pattern, $this->value) ) |
|
2094 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2095 | + if ( ! preg_match($pattern, $this->value)) |
|
2096 | 2096 | { |
2097 | 2097 | $message = $message ?: $this->overrideError; |
2098 | 2098 | $message = sprintf( |
@@ -2114,7 +2114,7 @@ discard block |
||
2114 | 2114 | */ |
2115 | 2115 | public function alnum($message = null, $propertyPath = null) |
2116 | 2116 | { |
2117 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2117 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2118 | 2118 | { |
2119 | 2119 | return $this; |
2120 | 2120 | } |
@@ -2145,11 +2145,11 @@ discard block |
||
2145 | 2145 | */ |
2146 | 2146 | public function true($message = null, $propertyPath = null) |
2147 | 2147 | { |
2148 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2148 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2149 | 2149 | { |
2150 | 2150 | return $this; |
2151 | 2151 | } |
2152 | - if ( $this->value !== true ) |
|
2152 | + if ($this->value !== true) |
|
2153 | 2153 | { |
2154 | 2154 | $message = $message ?: $this->overrideError; |
2155 | 2155 | $message = sprintf( |
@@ -2171,11 +2171,11 @@ discard block |
||
2171 | 2171 | */ |
2172 | 2172 | public function truthy($message = null, $propertyPath = null) |
2173 | 2173 | { |
2174 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2174 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2175 | 2175 | { |
2176 | 2176 | return $this; |
2177 | 2177 | } |
2178 | - if ( ! $this->value ) |
|
2178 | + if ( ! $this->value) |
|
2179 | 2179 | { |
2180 | 2180 | $message = $message ?: $this->overrideError; |
2181 | 2181 | $message = sprintf( |
@@ -2197,11 +2197,11 @@ discard block |
||
2197 | 2197 | */ |
2198 | 2198 | public function false($message = null, $propertyPath = null) |
2199 | 2199 | { |
2200 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2200 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2201 | 2201 | { |
2202 | 2202 | return $this; |
2203 | 2203 | } |
2204 | - if ( $this->value !== false ) |
|
2204 | + if ($this->value !== false) |
|
2205 | 2205 | { |
2206 | 2206 | $message = $message ?: $this->overrideError; |
2207 | 2207 | $message = sprintf( |
@@ -2223,11 +2223,11 @@ discard block |
||
2223 | 2223 | */ |
2224 | 2224 | public function notFalse($message = null, $propertyPath = null) |
2225 | 2225 | { |
2226 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2226 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2227 | 2227 | { |
2228 | 2228 | return $this; |
2229 | 2229 | } |
2230 | - if ( $this->value === false ) |
|
2230 | + if ($this->value === false) |
|
2231 | 2231 | { |
2232 | 2232 | $message = $message ?: $this->overrideError; |
2233 | 2233 | $message = sprintf( |
@@ -2249,11 +2249,11 @@ discard block |
||
2249 | 2249 | */ |
2250 | 2250 | public function classExists($message = null, $propertyPath = null) |
2251 | 2251 | { |
2252 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2252 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2253 | 2253 | { |
2254 | 2254 | return $this; |
2255 | 2255 | } |
2256 | - if ( !class_exists($this->value) ) |
|
2256 | + if ( ! class_exists($this->value)) |
|
2257 | 2257 | { |
2258 | 2258 | $message = $message ?: $this->overrideError; |
2259 | 2259 | $message = sprintf( |
@@ -2276,12 +2276,12 @@ discard block |
||
2276 | 2276 | */ |
2277 | 2277 | public function implementsInterface($interfaceName, $message = null, $propertyPath = null) |
2278 | 2278 | { |
2279 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2279 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2280 | 2280 | { |
2281 | 2281 | return $this; |
2282 | 2282 | } |
2283 | 2283 | $reflection = new \ReflectionClass($this->value); |
2284 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
2284 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
2285 | 2285 | { |
2286 | 2286 | $message = $message ?: $this->overrideError; |
2287 | 2287 | $message = sprintf( |
@@ -2289,7 +2289,7 @@ discard block |
||
2289 | 2289 | $this->stringify($this->value), |
2290 | 2290 | $this->stringify($interfaceName) |
2291 | 2291 | ); |
2292 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, ['interface' => $interfaceName]); |
|
2292 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, [ 'interface' => $interfaceName ]); |
|
2293 | 2293 | } |
2294 | 2294 | return $this; |
2295 | 2295 | } |
@@ -2310,11 +2310,11 @@ discard block |
||
2310 | 2310 | */ |
2311 | 2311 | public function isJsonString($message = null, $propertyPath = null) |
2312 | 2312 | { |
2313 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2313 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2314 | 2314 | { |
2315 | 2315 | return $this; |
2316 | 2316 | } |
2317 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
2317 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
2318 | 2318 | { |
2319 | 2319 | $message = $message ?: $this->overrideError; |
2320 | 2320 | $message = sprintf( |
@@ -2338,16 +2338,16 @@ discard block |
||
2338 | 2338 | */ |
2339 | 2339 | public function uuid($message = null, $propertyPath = null) |
2340 | 2340 | { |
2341 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2341 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2342 | 2342 | { |
2343 | 2343 | return $this; |
2344 | 2344 | } |
2345 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
2346 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
2345 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
2346 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
2347 | 2347 | { |
2348 | 2348 | return $this; |
2349 | 2349 | } |
2350 | - 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) ) |
|
2350 | + 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)) |
|
2351 | 2351 | { |
2352 | 2352 | $message = $message ?: $this->overrideError; |
2353 | 2353 | $message = sprintf( |
@@ -2370,11 +2370,11 @@ discard block |
||
2370 | 2370 | */ |
2371 | 2371 | public function count($count, $message = null, $propertyPath = null) |
2372 | 2372 | { |
2373 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2373 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2374 | 2374 | { |
2375 | 2375 | return $this; |
2376 | 2376 | } |
2377 | - if ( $count !== count($this->value) ) |
|
2377 | + if ($count !== count($this->value)) |
|
2378 | 2378 | { |
2379 | 2379 | $message = $message ?: $this->overrideError; |
2380 | 2380 | $message = sprintf( |
@@ -2382,7 +2382,7 @@ discard block |
||
2382 | 2382 | $this->stringify($this->value), |
2383 | 2383 | $this->stringify($count) |
2384 | 2384 | ); |
2385 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, ['count' => $count]); |
|
2385 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, [ 'count' => $count ]); |
|
2386 | 2386 | } |
2387 | 2387 | return $this; |
2388 | 2388 | } |
@@ -2395,24 +2395,24 @@ discard block |
||
2395 | 2395 | */ |
2396 | 2396 | protected function doAllOrNullOr($func, $args) |
2397 | 2397 | { |
2398 | - if ( $this->nullOr && is_null($this->value) ) |
|
2398 | + if ($this->nullOr && is_null($this->value)) |
|
2399 | 2399 | { |
2400 | 2400 | return true; |
2401 | 2401 | } |
2402 | - if ( $this->emptyOr && empty($this->value) ) |
|
2402 | + if ($this->emptyOr && empty($this->value)) |
|
2403 | 2403 | { |
2404 | 2404 | return true; |
2405 | 2405 | } |
2406 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
2406 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
2407 | 2407 | { |
2408 | - foreach ( $this->value as $idx => $value ) |
|
2408 | + foreach ($this->value as $idx => $value) |
|
2409 | 2409 | { |
2410 | 2410 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
2411 | - call_user_func_array([$object, $func], $args); |
|
2411 | + call_user_func_array([ $object, $func ], $args); |
|
2412 | 2412 | } |
2413 | 2413 | return true; |
2414 | 2414 | } |
2415 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
2415 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
2416 | 2416 | } |
2417 | 2417 | |
2418 | 2418 | /** |
@@ -2425,12 +2425,12 @@ discard block |
||
2425 | 2425 | */ |
2426 | 2426 | public function choicesNotEmpty(array $choices, $message = null, $propertyPath = null) |
2427 | 2427 | { |
2428 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2428 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2429 | 2429 | { |
2430 | 2430 | return $this; |
2431 | 2431 | } |
2432 | 2432 | $this->notEmpty($message, $propertyPath); |
2433 | - foreach ( $choices as $choice ) |
|
2433 | + foreach ($choices as $choice) |
|
2434 | 2434 | { |
2435 | 2435 | $this->notEmptyKey($choice, $message, $propertyPath); |
2436 | 2436 | } |
@@ -2448,12 +2448,12 @@ discard block |
||
2448 | 2448 | */ |
2449 | 2449 | public function methodExists($object, $message = null, $propertyPath = null) |
2450 | 2450 | { |
2451 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2451 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2452 | 2452 | { |
2453 | 2453 | return $this; |
2454 | 2454 | } |
2455 | 2455 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath); |
2456 | - if ( !method_exists($object, $this->value) ) |
|
2456 | + if ( ! method_exists($object, $this->value)) |
|
2457 | 2457 | { |
2458 | 2458 | $message = $message ?: $this->overrideError; |
2459 | 2459 | $message = sprintf( |
@@ -2475,11 +2475,11 @@ discard block |
||
2475 | 2475 | */ |
2476 | 2476 | public function isObject($message = null, $propertyPath = null) |
2477 | 2477 | { |
2478 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2478 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2479 | 2479 | { |
2480 | 2480 | return $this; |
2481 | 2481 | } |
2482 | - if ( !is_object($this->value) ) |
|
2482 | + if ( ! is_object($this->value)) |
|
2483 | 2483 | { |
2484 | 2484 | $message = $message ?: $this->overrideError; |
2485 | 2485 | $message = sprintf( |
@@ -2499,32 +2499,32 @@ discard block |
||
2499 | 2499 | */ |
2500 | 2500 | private function stringify($value) |
2501 | 2501 | { |
2502 | - if ( is_bool($value) ) |
|
2502 | + if (is_bool($value)) |
|
2503 | 2503 | { |
2504 | 2504 | return $value ? '<TRUE>' : '<FALSE>'; |
2505 | 2505 | } |
2506 | - if ( is_scalar($value) ) |
|
2506 | + if (is_scalar($value)) |
|
2507 | 2507 | { |
2508 | 2508 | $val = (string)$value; |
2509 | - if ( strlen($val) > 100 ) |
|
2509 | + if (strlen($val) > 100) |
|
2510 | 2510 | { |
2511 | - $val = substr($val, 0, 97) . '...'; |
|
2511 | + $val = substr($val, 0, 97).'...'; |
|
2512 | 2512 | } |
2513 | 2513 | return $val; |
2514 | 2514 | } |
2515 | - if ( is_array($value) ) |
|
2515 | + if (is_array($value)) |
|
2516 | 2516 | { |
2517 | 2517 | return '<ARRAY>'; |
2518 | 2518 | } |
2519 | - if ( is_object($value) ) |
|
2519 | + if (is_object($value)) |
|
2520 | 2520 | { |
2521 | 2521 | return get_class($value); |
2522 | 2522 | } |
2523 | - if ( is_resource($value) ) |
|
2523 | + if (is_resource($value)) |
|
2524 | 2524 | { |
2525 | 2525 | return '<RESOURCE>'; |
2526 | 2526 | } |
2527 | - if ( $value === null ) |
|
2527 | + if ($value === null) |
|
2528 | 2528 | { |
2529 | 2529 | return '<NULL>'; |
2530 | 2530 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | |
4 | -require_once __DIR__ . '/../../../../vendor/autoload.php'; |
|
4 | +require_once __DIR__.'/../../../../vendor/autoload.php'; |
|
5 | 5 | |
6 | 6 | use function Terah\Assert\Assert; |
7 | 7 | |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | echo "Benchmarking static Terah\\Assert"; |
15 | 15 | $start = microtime(true); |
16 | 16 | |
17 | -for ( $i = 0 ; $i < 100000 ; $i++ ) |
|
17 | +for ($i = 0; $i < 100000; $i++) |
|
18 | 18 | { |
19 | 19 | Assert::that(true)->true(); |
20 | 20 | } |
21 | 21 | $time = microtime(true) - $start; |
22 | -echo "Taken: $time" . PHP_EOL; |
|
22 | +echo "Taken: $time".PHP_EOL; |
|
23 | 23 | |
24 | 24 | echo "Benchmarking new Terah\\Assert"; |
25 | 25 | $start = microtime(true); |
26 | 26 | |
27 | -for ( $i = 0 ; $i < 100000 ; $i++ ) |
|
27 | +for ($i = 0; $i < 100000; $i++) |
|
28 | 28 | { |
29 | 29 | Assert(true)->true(); |
30 | 30 | } |
31 | 31 | $time = microtime(true) - $start; |
32 | -echo "Taken: $time" . PHP_EOL; |
|
32 | +echo "Taken: $time".PHP_EOL; |
|
33 | 33 | |
34 | 34 | echo "Benchmarking fluent Beberlei"; |
35 | 35 | $start = microtime(true); |
36 | 36 | |
37 | -for ( $i = 0 ; $i < 100000 ; $i++ ) |
|
37 | +for ($i = 0; $i < 100000; $i++) |
|
38 | 38 | { |
39 | 39 | Beberlei\that(true)->true(); |
40 | 40 | } |
41 | 41 | $time = microtime(true) - $start; |
42 | -echo "Taken: $time" . PHP_EOL; |
|
42 | +echo "Taken: $time".PHP_EOL; |
|
43 | 43 |
@@ -10,5 +10,5 @@ |
||
10 | 10 | * |
11 | 11 | * @var string |
12 | 12 | */ |
13 | - protected $exceptionClass = 'Terah\Assert\ValidationFailedException'; |
|
13 | + protected $exceptionClass = 'Terah\Assert\ValidationFailedException'; |
|
14 | 14 | } |
15 | 15 | \ 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 | /** |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param array $constraints |
29 | 29 | * @param string $level |
30 | 30 | */ |
31 | - public function __construct(string $message, int $code, string $propertyPath = null, $value, array $constraints=[], string $level='critical') |
|
31 | + public function __construct(string $message, int $code, string $propertyPath = null, $value, array $constraints = [ ], string $level = 'critical') |
|
32 | 32 | { |
33 | 33 | parent::__construct($message, $code); |
34 | 34 | $this->propertyPath = $propertyPath; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $calling_location = $this->getCallingFileAndLine(); |
51 | 51 | |
52 | - return $this->propertyPath . ' in ' .$calling_location; |
|
52 | + return $this->propertyPath.' in '.$calling_location; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -73,15 +73,15 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function getCallingFileAndLine() : string |
75 | 75 | { |
76 | - foreach ( $this->getTrace() as $trace ) |
|
76 | + foreach ($this->getTrace() as $trace) |
|
77 | 77 | { |
78 | 78 | $trace = (object)$trace; |
79 | - if ( empty($trace->file) ) |
|
79 | + if (empty($trace->file)) |
|
80 | 80 | { |
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | $file = static::beforeLast('.php', static::afterLast('/', $trace->file)); |
84 | - if ( in_array($file, ['AssertionChain', 'Assertion']) ) |
|
84 | + if (in_array($file, [ 'AssertionChain', 'Assertion' ])) |
|
85 | 85 | { |
86 | 86 | continue; |
87 | 87 | } |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * @param bool $return_original |
117 | 117 | * @return string |
118 | 118 | */ |
119 | - public static function afterLast(string $needle, string $haystack, bool $return_original=false) : string |
|
119 | + public static function afterLast(string $needle, string $haystack, bool $return_original = false) : string |
|
120 | 120 | { |
121 | - if ( static::strrevpos($haystack, $needle) !== -1 ) |
|
121 | + if (static::strrevpos($haystack, $needle) !== -1) |
|
122 | 122 | { |
123 | 123 | return mb_substr($haystack, static::strrevpos($haystack, $needle) + mb_strlen($needle)); |
124 | 124 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public static function beforeLast(string $needle, string $haystack) : string |
147 | 147 | { |
148 | - $position = static::strrevpos($haystack, $needle); |
|
148 | + $position = static::strrevpos($haystack, $needle); |
|
149 | 149 | |
150 | 150 | return $position === -1 ? '' : mb_substr($haystack, 0, static::strrevpos($haystack, $needle)); |
151 | 151 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | * @param bool|false $throwValidationError |
8 | 8 | * @return Assert |
9 | 9 | */ |
10 | -function Assert($value, $throwValidationError=false) |
|
10 | +function Assert($value, $throwValidationError = false) |
|
11 | 11 | { |
12 | 12 | $assert = new Assert($value); |
13 | - if ( ! $throwValidationError ) |
|
13 | + if ( ! $throwValidationError) |
|
14 | 14 | { |
15 | 15 | return $assert; |
16 | 16 | } |
@@ -25,23 +25,23 @@ discard block |
||
25 | 25 | * @param string $level |
26 | 26 | * @return Assert |
27 | 27 | */ |
28 | -function Validate($value, $name='', $code=0, $error='', $level=Assert::WARNING) |
|
28 | +function Validate($value, $name = '', $code = 0, $error = '', $level = Assert::WARNING) |
|
29 | 29 | { |
30 | 30 | $assert = new Assert($value); |
31 | 31 | $assert->setExceptionClass('Terah\Assert\ValidationFailedException'); |
32 | - if ( $name ) |
|
32 | + if ($name) |
|
33 | 33 | { |
34 | 34 | $assert->name($name); |
35 | 35 | } |
36 | - if ( $code ) |
|
36 | + if ($code) |
|
37 | 37 | { |
38 | 38 | $assert->code($code); |
39 | 39 | } |
40 | - if ( $error ) |
|
40 | + if ($error) |
|
41 | 41 | { |
42 | 42 | $assert->error($error); |
43 | 43 | } |
44 | - if ( $level ) |
|
44 | + if ($level) |
|
45 | 45 | { |
46 | 46 | $assert->level($level); |
47 | 47 | } |