@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | |
3 | 3 | namespace Terah\Assert; |
4 | 4 | /** |
@@ -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 | |
@@ -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 | } |
@@ -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,21 +29,21 @@ discard block |
||
29 | 29 | * @param array $constraints |
30 | 30 | * @param string $level |
31 | 31 | */ |
32 | - public function __construct(string $message, int $code, string $propertyPath = null, $value, array $constraints=[], string $level='critical') |
|
32 | + public function __construct(string $message, int $code, string $propertyPath = null, $value, array $constraints = [ ], string $level = 'critical') |
|
33 | 33 | { |
34 | 34 | parent::__construct($message, $code); |
35 | 35 | $this->propertyPath = $propertyPath; |
36 | 36 | $this->value = $value; |
37 | 37 | $this->constraints = $constraints; |
38 | 38 | $this->level = $level; |
39 | - foreach ( $this->getTrace() as $point ) |
|
39 | + foreach ($this->getTrace() as $point) |
|
40 | 40 | { |
41 | - if ( $this->location ) |
|
41 | + if ($this->location) |
|
42 | 42 | { |
43 | 43 | continue; |
44 | 44 | } |
45 | - $class = $point['class'] ?: ''; |
|
46 | - if ( $class !== 'Terah\\Assert\\Assert' ) |
|
45 | + $class = $point[ 'class' ] ?: ''; |
|
46 | + if ($class !== 'Terah\\Assert\\Assert') |
|
47 | 47 | { |
48 | 48 | $this->location = (object)$point; |
49 | 49 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $calling_location = $this->getCallingFileAndLine(); |
65 | 65 | |
66 | - return $this->propertyPath . ' in ' .$calling_location; |
|
66 | + return $this->propertyPath.' in '.$calling_location; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function getCallingFileAndLine() : string |
89 | 89 | { |
90 | - foreach ( $this->getTrace() as $trace ) |
|
90 | + foreach ($this->getTrace() as $trace) |
|
91 | 91 | { |
92 | 92 | $trace = (object)$trace; |
93 | - if ( empty($trace->file) ) |
|
93 | + if (empty($trace->file)) |
|
94 | 94 | { |
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | $file = static::beforeLast('.php', static::afterLast('/', $trace->file)); |
98 | - if ( in_array($file, ['AssertionChain', 'Assertion']) ) |
|
98 | + if (in_array($file, [ 'AssertionChain', 'Assertion' ])) |
|
99 | 99 | { |
100 | 100 | continue; |
101 | 101 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * @param bool $return_original |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public static function afterLast(string $needle, string $haystack, bool $return_original=false) : string |
|
141 | + public static function afterLast(string $needle, string $haystack, bool $return_original = false) : string |
|
142 | 142 | { |
143 | - if ( static::strrevpos($haystack, $needle) !== -1 ) |
|
143 | + if (static::strrevpos($haystack, $needle) !== -1) |
|
144 | 144 | { |
145 | 145 | return mb_substr($haystack, static::strrevpos($haystack, $needle) + mb_strlen($needle)); |
146 | 146 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public static function beforeLast(string $needle, string $haystack) : string |
169 | 169 | { |
170 | - $position = static::strrevpos($haystack, $needle); |
|
170 | + $position = static::strrevpos($haystack, $needle); |
|
171 | 171 | |
172 | 172 | return $position === -1 ? '' : mb_substr($haystack, 0, static::strrevpos($haystack, $needle)); |
173 | 173 | } |
@@ -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 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @var string |
131 | 131 | */ |
132 | - protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
132 | + protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param mixed $value |
@@ -147,22 +147,22 @@ discard block |
||
147 | 147 | * @param string $level |
148 | 148 | * @return Assert |
149 | 149 | */ |
150 | - public static function that($value, $name='', $code=0, $error='', $level=Assert::WARNING) |
|
150 | + public static function that($value, $name = '', $code = 0, $error = '', $level = Assert::WARNING) |
|
151 | 151 | { |
152 | 152 | $assert = new static($value); |
153 | - if ( $name ) |
|
153 | + if ($name) |
|
154 | 154 | { |
155 | 155 | $assert->name($name); |
156 | 156 | } |
157 | - if ( $code ) |
|
157 | + if ($code) |
|
158 | 158 | { |
159 | 159 | $assert->code($code); |
160 | 160 | } |
161 | - if ( $error ) |
|
161 | + if ($error) |
|
162 | 162 | { |
163 | 163 | $assert->error($error); |
164 | 164 | } |
165 | - if ( $level ) |
|
165 | + if ($level) |
|
166 | 166 | { |
167 | 167 | $assert->level($level); |
168 | 168 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $level |
232 | 232 | * @return AssertionFailedException |
233 | 233 | */ |
234 | - protected function createException($message, $code, $propertyPath, array $constraints = [], $level=null) |
|
234 | + protected function createException($message, $code, $propertyPath, array $constraints = [ ], $level = null) |
|
235 | 235 | { |
236 | 236 | $exceptionClass = $this->exceptionClass; |
237 | 237 | $propertyPath = is_null($propertyPath) ? $this->propertyPath : $propertyPath; |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | */ |
302 | 302 | public function eq($value2, $message = null, $propertyPath = null) |
303 | 303 | { |
304 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
304 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
305 | 305 | { |
306 | 306 | return $this; |
307 | 307 | } |
308 | - if ( $this->value != $value2 ) |
|
308 | + if ($this->value != $value2) |
|
309 | 309 | { |
310 | 310 | $message = $message ?: $this->overrideError; |
311 | 311 | $message = sprintf( |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $this->stringify($this->value), |
314 | 314 | $this->stringify($value2) |
315 | 315 | ); |
316 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
316 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
317 | 317 | } |
318 | 318 | return $this; |
319 | 319 | } |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | */ |
329 | 329 | public function greaterThan($value2, $message = null, $propertyPath = null) |
330 | 330 | { |
331 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
331 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
332 | 332 | { |
333 | 333 | return $this; |
334 | 334 | } |
335 | - if ( ! ( $this->value > $value2 ) ) |
|
335 | + if ( ! ($this->value > $value2)) |
|
336 | 336 | { |
337 | 337 | $message = $message ?: $this->overrideError; |
338 | 338 | $message = sprintf( |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | $this->stringify($this->value), |
341 | 341 | $this->stringify($value2) |
342 | 342 | ); |
343 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
343 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
344 | 344 | } |
345 | 345 | return $this; |
346 | 346 | } |
@@ -355,11 +355,11 @@ discard block |
||
355 | 355 | */ |
356 | 356 | public function greaterThanOrEq($value2, $message = null, $propertyPath = null) |
357 | 357 | { |
358 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
358 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
359 | 359 | { |
360 | 360 | return $this; |
361 | 361 | } |
362 | - if ( ! ( $this->value >= $value2 ) ) |
|
362 | + if ( ! ($this->value >= $value2)) |
|
363 | 363 | { |
364 | 364 | $message = $message ?: $this->overrideError; |
365 | 365 | $message = sprintf( |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $this->stringify($this->value), |
368 | 368 | $this->stringify($value2) |
369 | 369 | ); |
370 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
370 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
371 | 371 | } |
372 | 372 | return $this; |
373 | 373 | } |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function lessThan($value2, $message = null, $propertyPath = null) |
384 | 384 | { |
385 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
385 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
386 | 386 | { |
387 | 387 | return $this; |
388 | 388 | } |
389 | - if ( ! ( $this->value < $value2 ) ) |
|
389 | + if ( ! ($this->value < $value2)) |
|
390 | 390 | { |
391 | 391 | $message = $message ?: $this->overrideError; |
392 | 392 | $message = sprintf( |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $this->stringify($this->value), |
395 | 395 | $this->stringify($value2) |
396 | 396 | ); |
397 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]); |
|
397 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, [ 'expected' => $value2 ]); |
|
398 | 398 | } |
399 | 399 | return $this; |
400 | 400 | } |
@@ -409,11 +409,11 @@ discard block |
||
409 | 409 | */ |
410 | 410 | public function lessThanOrEq($value2, $message = null, $propertyPath = null) |
411 | 411 | { |
412 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
412 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
413 | 413 | { |
414 | 414 | return $this; |
415 | 415 | } |
416 | - if ( ! ( $this->value <= $value2 ) ) |
|
416 | + if ( ! ($this->value <= $value2)) |
|
417 | 417 | { |
418 | 418 | $message = $message ?: $this->overrideError; |
419 | 419 | $message = sprintf( |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | $this->stringify($this->value), |
422 | 422 | $this->stringify($value2) |
423 | 423 | ); |
424 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]); |
|
424 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
425 | 425 | } |
426 | 426 | return $this; |
427 | 427 | } |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function same($value2, $message = null, $propertyPath = null) |
439 | 439 | { |
440 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
440 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
441 | 441 | { |
442 | 442 | return $this; |
443 | 443 | } |
444 | - if ( $this->value !== $value2 ) |
|
444 | + if ($this->value !== $value2) |
|
445 | 445 | { |
446 | 446 | $message = $message ?: $this->overrideError; |
447 | 447 | $message = sprintf( |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | $this->stringify($this->value), |
450 | 450 | $this->stringify($value2) |
451 | 451 | ); |
452 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, ['expected' => $value2]); |
|
452 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
453 | 453 | } |
454 | 454 | return $this; |
455 | 455 | } |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | */ |
466 | 466 | public function notEq($value2, $message = null, $propertyPath = null) |
467 | 467 | { |
468 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
468 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
469 | 469 | { |
470 | 470 | return $this; |
471 | 471 | } |
472 | - if ( $this->value == $value2 ) |
|
472 | + if ($this->value == $value2) |
|
473 | 473 | { |
474 | 474 | $message = $message ?: $this->overrideError; |
475 | 475 | $message = sprintf( |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $this->stringify($this->value), |
478 | 478 | $this->stringify($value2) |
479 | 479 | ); |
480 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, ['expected' => $value2]); |
|
480 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
481 | 481 | } |
482 | 482 | return $this; |
483 | 483 | } |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public function isCallable($message = null, $propertyPath = null) |
493 | 493 | { |
494 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
494 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
495 | 495 | { |
496 | 496 | return $this; |
497 | 497 | } |
498 | - if ( !is_callable($this->value) ) |
|
498 | + if ( ! is_callable($this->value)) |
|
499 | 499 | { |
500 | 500 | $message = $message ?: $this->overrideError; |
501 | 501 | $message = sprintf( |
@@ -518,11 +518,11 @@ discard block |
||
518 | 518 | */ |
519 | 519 | public function notSame($value2, $message = null, $propertyPath = null) |
520 | 520 | { |
521 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
521 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
522 | 522 | { |
523 | 523 | return $this; |
524 | 524 | } |
525 | - if ( $this->value === $value2 ) |
|
525 | + if ($this->value === $value2) |
|
526 | 526 | { |
527 | 527 | $message = $message ?: $this->overrideError; |
528 | 528 | $message = sprintf( |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | $this->stringify($this->value), |
531 | 531 | $this->stringify($value2) |
532 | 532 | ); |
533 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, ['expected' => $value2]); |
|
533 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
534 | 534 | } |
535 | 535 | return $this; |
536 | 536 | } |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | * @return Assert |
555 | 555 | * @throws AssertionFailedException |
556 | 556 | */ |
557 | - public function unsignedInt($message=null, $propertyPath=null) |
|
557 | + public function unsignedInt($message = null, $propertyPath = null) |
|
558 | 558 | { |
559 | 559 | $message = $message ?: $this->overrideError; |
560 | 560 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | { |
586 | 586 | $message = $message ?: $this->overrideError; |
587 | 587 | $message = $message ?: 'Value "%s" is not a valid status.'; |
588 | - return $this->integer($message, $propertyPath)->inArray([-1, 0, 1]); |
|
588 | + return $this->integer($message, $propertyPath)->inArray([-1, 0, 1 ]); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -629,11 +629,11 @@ discard block |
||
629 | 629 | */ |
630 | 630 | public function integer($message = null, $propertyPath = null) |
631 | 631 | { |
632 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
632 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
633 | 633 | { |
634 | 634 | return $this; |
635 | 635 | } |
636 | - if ( !is_int($this->value) ) |
|
636 | + if ( ! is_int($this->value)) |
|
637 | 637 | { |
638 | 638 | $message = $message ?: $this->overrideError; |
639 | 639 | $message = sprintf( |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public function float($message = null, $propertyPath = null) |
657 | 657 | { |
658 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
658 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
659 | 659 | { |
660 | 660 | return $this; |
661 | 661 | } |
662 | - if ( ! is_float($this->value) ) |
|
662 | + if ( ! is_float($this->value)) |
|
663 | 663 | { |
664 | 664 | $message = $message ?: $this->overrideError; |
665 | 665 | $message = sprintf( |
@@ -681,11 +681,11 @@ discard block |
||
681 | 681 | */ |
682 | 682 | public function digit($message = null, $propertyPath = null) |
683 | 683 | { |
684 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
684 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
685 | 685 | { |
686 | 686 | return $this; |
687 | 687 | } |
688 | - if ( ! ctype_digit((string)$this->value) ) |
|
688 | + if ( ! ctype_digit((string)$this->value)) |
|
689 | 689 | { |
690 | 690 | $message = $message ?: $this->overrideError; |
691 | 691 | $message = sprintf( |
@@ -707,12 +707,12 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function date($message = null, $propertyPath = null) |
709 | 709 | { |
710 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
710 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
711 | 711 | { |
712 | 712 | return $this; |
713 | 713 | } |
714 | 714 | $this->notEmpty($message, $propertyPath); |
715 | - if ( strtotime($this->value) === false ) |
|
715 | + if (strtotime($this->value) === false) |
|
716 | 716 | { |
717 | 717 | $message = $message ?: $this->overrideError; |
718 | 718 | $message = sprintf( |
@@ -734,11 +734,11 @@ discard block |
||
734 | 734 | */ |
735 | 735 | public function integerish($message = null, $propertyPath = null) |
736 | 736 | { |
737 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
737 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
738 | 738 | { |
739 | 739 | return $this; |
740 | 740 | } |
741 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
741 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
742 | 742 | { |
743 | 743 | $message = $message ?: $this->overrideError; |
744 | 744 | $message = sprintf( |
@@ -760,11 +760,11 @@ discard block |
||
760 | 760 | */ |
761 | 761 | public function boolean($message = null, $propertyPath = null) |
762 | 762 | { |
763 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
763 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
764 | 764 | { |
765 | 765 | return $this; |
766 | 766 | } |
767 | - if ( ! is_bool($this->value) ) |
|
767 | + if ( ! is_bool($this->value)) |
|
768 | 768 | { |
769 | 769 | $message = $message ?: $this->overrideError; |
770 | 770 | $message = sprintf( |
@@ -786,11 +786,11 @@ discard block |
||
786 | 786 | */ |
787 | 787 | public function scalar($message = null, $propertyPath = null) |
788 | 788 | { |
789 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
789 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
790 | 790 | { |
791 | 791 | return $this; |
792 | 792 | } |
793 | - if ( ! is_scalar($this->value) ) |
|
793 | + if ( ! is_scalar($this->value)) |
|
794 | 794 | { |
795 | 795 | $message = $message ?: $this->overrideError; |
796 | 796 | $message = sprintf( |
@@ -812,11 +812,11 @@ discard block |
||
812 | 812 | */ |
813 | 813 | public function notEmpty($message = null, $propertyPath = null) |
814 | 814 | { |
815 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
815 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
816 | 816 | { |
817 | 817 | return $this; |
818 | 818 | } |
819 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
819 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
820 | 820 | { |
821 | 821 | $message = $message ?: $this->overrideError; |
822 | 822 | $message = sprintf( |
@@ -838,11 +838,11 @@ discard block |
||
838 | 838 | */ |
839 | 839 | public function noContent($message = null, $propertyPath = null) |
840 | 840 | { |
841 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
841 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
842 | 842 | { |
843 | 843 | return $this; |
844 | 844 | } |
845 | - if ( !empty( $this->value ) ) |
|
845 | + if ( ! empty($this->value)) |
|
846 | 846 | { |
847 | 847 | $message = $message ?: $this->overrideError; |
848 | 848 | $message = sprintf( |
@@ -864,11 +864,11 @@ discard block |
||
864 | 864 | */ |
865 | 865 | public function notNull($message = null, $propertyPath = null) |
866 | 866 | { |
867 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
867 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
868 | 868 | { |
869 | 869 | return $this; |
870 | 870 | } |
871 | - if ( $this->value === null ) |
|
871 | + if ($this->value === null) |
|
872 | 872 | { |
873 | 873 | $message = $message ?: $this->overrideError; |
874 | 874 | $message = sprintf( |
@@ -890,11 +890,11 @@ discard block |
||
890 | 890 | */ |
891 | 891 | public function string($message = null, $propertyPath = null) |
892 | 892 | { |
893 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
893 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
894 | 894 | { |
895 | 895 | return $this; |
896 | 896 | } |
897 | - if ( !is_string($this->value) ) |
|
897 | + if ( ! is_string($this->value)) |
|
898 | 898 | { |
899 | 899 | $message = $message ?: $this->overrideError; |
900 | 900 | $message = sprintf( |
@@ -916,21 +916,21 @@ discard block |
||
916 | 916 | * @return Assert |
917 | 917 | * @throws AssertionFailedException |
918 | 918 | */ |
919 | - public function regex($pattern, $message=null, $propertyPath=null) |
|
919 | + public function regex($pattern, $message = null, $propertyPath = null) |
|
920 | 920 | { |
921 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
921 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
922 | 922 | { |
923 | 923 | return $this; |
924 | 924 | } |
925 | 925 | $this->string($message, $propertyPath); |
926 | - if ( ! preg_match($pattern, $this->value) ) |
|
926 | + if ( ! preg_match($pattern, $this->value)) |
|
927 | 927 | { |
928 | 928 | $message = $message ?: $this->overrideError; |
929 | 929 | $message = sprintf( |
930 | 930 | $message ?: 'Value "%s" does not match expression.', |
931 | 931 | $this->stringify($this->value) |
932 | 932 | ); |
933 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
933 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
934 | 934 | } |
935 | 935 | return $this; |
936 | 936 | } |
@@ -943,13 +943,13 @@ discard block |
||
943 | 943 | */ |
944 | 944 | public function ipAddress($message = null, $propertyPath = null) |
945 | 945 | { |
946 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
946 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
947 | 947 | { |
948 | 948 | return $this; |
949 | 949 | } |
950 | 950 | $this->string($message, $propertyPath); |
951 | - $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])$/'; |
|
952 | - if ( ! preg_match($pattern, $this->value) ) |
|
951 | + $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])$/'; |
|
952 | + if ( ! preg_match($pattern, $this->value)) |
|
953 | 953 | { |
954 | 954 | $message = $message ?: $this->overrideError; |
955 | 955 | $message = sprintf( |
@@ -970,19 +970,19 @@ discard block |
||
970 | 970 | */ |
971 | 971 | public function notRegex($pattern, $message = null, $propertyPath = null) |
972 | 972 | { |
973 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
973 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
974 | 974 | { |
975 | 975 | return $this; |
976 | 976 | } |
977 | 977 | $this->string($message, $propertyPath); |
978 | - if ( preg_match($pattern, $this->value) ) |
|
978 | + if (preg_match($pattern, $this->value)) |
|
979 | 979 | { |
980 | 980 | $message = $message ?: $this->overrideError; |
981 | 981 | $message = sprintf( |
982 | 982 | $message ?: 'Value "%s" does not match expression.', |
983 | 983 | $this->stringify($this->value) |
984 | 984 | ); |
985 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
985 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
986 | 986 | } |
987 | 987 | return $this; |
988 | 988 | } |
@@ -999,12 +999,12 @@ discard block |
||
999 | 999 | */ |
1000 | 1000 | public function length($length, $message = null, $propertyPath = null, $encoding = 'utf8') |
1001 | 1001 | { |
1002 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1002 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1003 | 1003 | { |
1004 | 1004 | return $this; |
1005 | 1005 | } |
1006 | 1006 | $this->string($message, $propertyPath); |
1007 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
1007 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
1008 | 1008 | { |
1009 | 1009 | $message = $message ?: $this->overrideError; |
1010 | 1010 | $message = sprintf( |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | $length, |
1014 | 1014 | mb_strlen($this->value, $encoding) |
1015 | 1015 | ); |
1016 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
1016 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
1017 | 1017 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $propertyPath, $constraints); |
1018 | 1018 | } |
1019 | 1019 | return $this; |
@@ -1031,22 +1031,22 @@ discard block |
||
1031 | 1031 | */ |
1032 | 1032 | public function minLength($minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1033 | 1033 | { |
1034 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1034 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1035 | 1035 | { |
1036 | 1036 | return $this; |
1037 | 1037 | } |
1038 | 1038 | $this->string($message, $propertyPath); |
1039 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1039 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1040 | 1040 | { |
1041 | 1041 | $message = $message ?: $this->overrideError; |
1042 | - $message = sprintf( |
|
1042 | + $message = sprintf( |
|
1043 | 1043 | $message |
1044 | 1044 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1045 | 1045 | $this->stringify($this->value), |
1046 | 1046 | $minLength, |
1047 | 1047 | mb_strlen($this->value, $encoding) |
1048 | 1048 | ); |
1049 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1049 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1050 | 1050 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
1051 | 1051 | } |
1052 | 1052 | return $this; |
@@ -1064,21 +1064,21 @@ discard block |
||
1064 | 1064 | */ |
1065 | 1065 | public function maxLength($maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1066 | 1066 | { |
1067 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1067 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1068 | 1068 | { |
1069 | 1069 | return $this; |
1070 | 1070 | } |
1071 | 1071 | $this->string($message, $propertyPath); |
1072 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1072 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1073 | 1073 | { |
1074 | 1074 | $message = $message ?: $this->overrideError; |
1075 | - $message = sprintf( |
|
1075 | + $message = sprintf( |
|
1076 | 1076 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1077 | 1077 | $this->stringify($this->value), |
1078 | 1078 | $maxLength, |
1079 | 1079 | mb_strlen($this->value, $encoding) |
1080 | 1080 | ); |
1081 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1081 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1082 | 1082 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1083 | 1083 | } |
1084 | 1084 | return $this; |
@@ -1097,34 +1097,34 @@ discard block |
||
1097 | 1097 | */ |
1098 | 1098 | public function betweenLength($minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1099 | 1099 | { |
1100 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1100 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1101 | 1101 | { |
1102 | 1102 | return $this; |
1103 | 1103 | } |
1104 | 1104 | $this->string($message, $propertyPath); |
1105 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1105 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1106 | 1106 | { |
1107 | 1107 | $message = $message ?: $this->overrideError; |
1108 | - $message = sprintf( |
|
1108 | + $message = sprintf( |
|
1109 | 1109 | $message |
1110 | 1110 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1111 | 1111 | $this->stringify($this->value), |
1112 | 1112 | $minLength, |
1113 | 1113 | mb_strlen($this->value, $encoding) |
1114 | 1114 | ); |
1115 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1115 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1116 | 1116 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
1117 | 1117 | } |
1118 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1118 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1119 | 1119 | { |
1120 | 1120 | $message = $message ?: $this->overrideError; |
1121 | - $message = sprintf( |
|
1121 | + $message = sprintf( |
|
1122 | 1122 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1123 | 1123 | $this->stringify($this->value), |
1124 | 1124 | $maxLength, |
1125 | 1125 | mb_strlen($this->value, $encoding) |
1126 | 1126 | ); |
1127 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1127 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1128 | 1128 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1129 | 1129 | } |
1130 | 1130 | return $this; |
@@ -1142,20 +1142,20 @@ discard block |
||
1142 | 1142 | */ |
1143 | 1143 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1144 | 1144 | { |
1145 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1145 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1146 | 1146 | { |
1147 | 1147 | return $this; |
1148 | 1148 | } |
1149 | 1149 | $this->string($message, $propertyPath); |
1150 | - if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1150 | + if (mb_strpos($this->value, $needle, null, $encoding) !== 0) |
|
1151 | 1151 | { |
1152 | 1152 | $message = $message ?: $this->overrideError; |
1153 | - $message = sprintf( |
|
1153 | + $message = sprintf( |
|
1154 | 1154 | $message ?: 'Value "%s" does not start with "%s".', |
1155 | 1155 | $this->stringify($this->value), |
1156 | 1156 | $this->stringify($needle) |
1157 | 1157 | ); |
1158 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1158 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1159 | 1159 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
1160 | 1160 | } |
1161 | 1161 | return $this; |
@@ -1173,21 +1173,21 @@ discard block |
||
1173 | 1173 | */ |
1174 | 1174 | public function endsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1175 | 1175 | { |
1176 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1176 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1177 | 1177 | { |
1178 | 1178 | return $this; |
1179 | 1179 | } |
1180 | 1180 | $this->string($message, $propertyPath); |
1181 | 1181 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
1182 | - if ( mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition ) |
|
1182 | + if (mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition) |
|
1183 | 1183 | { |
1184 | 1184 | $message = $message ?: $this->overrideError; |
1185 | - $message = sprintf( |
|
1185 | + $message = sprintf( |
|
1186 | 1186 | $message ?: 'Value "%s" does not end with "%s".', |
1187 | 1187 | $this->stringify($this->value), |
1188 | 1188 | $this->stringify($needle) |
1189 | 1189 | ); |
1190 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1190 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1191 | 1191 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $propertyPath, $constraints); |
1192 | 1192 | } |
1193 | 1193 | return $this; |
@@ -1205,20 +1205,20 @@ discard block |
||
1205 | 1205 | */ |
1206 | 1206 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1207 | 1207 | { |
1208 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1208 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1209 | 1209 | { |
1210 | 1210 | return $this; |
1211 | 1211 | } |
1212 | 1212 | $this->string($message, $propertyPath); |
1213 | - if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1213 | + if (mb_strpos($this->value, $needle, null, $encoding) === false) |
|
1214 | 1214 | { |
1215 | 1215 | $message = $message ?: $this->overrideError; |
1216 | - $message = sprintf( |
|
1216 | + $message = sprintf( |
|
1217 | 1217 | $message ?: 'Value "%s" does not contain "%s".', |
1218 | 1218 | $this->stringify($this->value), |
1219 | 1219 | $this->stringify($needle) |
1220 | 1220 | ); |
1221 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1221 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1222 | 1222 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
1223 | 1223 | } |
1224 | 1224 | return $this; |
@@ -1235,11 +1235,11 @@ discard block |
||
1235 | 1235 | */ |
1236 | 1236 | public function choice(array $choices, $message = null, $propertyPath = null) |
1237 | 1237 | { |
1238 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1238 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1239 | 1239 | { |
1240 | 1240 | return $this; |
1241 | 1241 | } |
1242 | - if ( !in_array($this->value, $choices, true) ) |
|
1242 | + if ( ! in_array($this->value, $choices, true)) |
|
1243 | 1243 | { |
1244 | 1244 | $message = $message ?: $this->overrideError; |
1245 | 1245 | $message = sprintf( |
@@ -1247,7 +1247,7 @@ discard block |
||
1247 | 1247 | $this->stringify($this->value), |
1248 | 1248 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
1249 | 1249 | ); |
1250 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, ['choices' => $choices]); |
|
1250 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, [ 'choices' => $choices ]); |
|
1251 | 1251 | } |
1252 | 1252 | return $this; |
1253 | 1253 | } |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | */ |
1265 | 1265 | public function inArray(array $choices, $message = null, $propertyPath = null) |
1266 | 1266 | { |
1267 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1267 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1268 | 1268 | { |
1269 | 1269 | return $this; |
1270 | 1270 | } |
@@ -1282,11 +1282,11 @@ discard block |
||
1282 | 1282 | */ |
1283 | 1283 | public function numeric($message = null, $propertyPath = null) |
1284 | 1284 | { |
1285 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1285 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1286 | 1286 | { |
1287 | 1287 | return $this; |
1288 | 1288 | } |
1289 | - if ( ! is_numeric($this->value) ) |
|
1289 | + if ( ! is_numeric($this->value)) |
|
1290 | 1290 | { |
1291 | 1291 | $message = $message ?: $this->overrideError; |
1292 | 1292 | $message = sprintf( |
@@ -1344,11 +1344,11 @@ discard block |
||
1344 | 1344 | */ |
1345 | 1345 | public function isArray($message = null, $propertyPath = null) |
1346 | 1346 | { |
1347 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1347 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1348 | 1348 | { |
1349 | 1349 | return $this; |
1350 | 1350 | } |
1351 | - if ( !is_array($this->value) ) |
|
1351 | + if ( ! is_array($this->value)) |
|
1352 | 1352 | { |
1353 | 1353 | $message = $message ?: $this->overrideError; |
1354 | 1354 | $message = sprintf( |
@@ -1370,11 +1370,11 @@ discard block |
||
1370 | 1370 | */ |
1371 | 1371 | public function isTraversable($message = null, $propertyPath = null) |
1372 | 1372 | { |
1373 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1373 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1374 | 1374 | { |
1375 | 1375 | return $this; |
1376 | 1376 | } |
1377 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
1377 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
1378 | 1378 | { |
1379 | 1379 | $message = $message ?: $this->overrideError; |
1380 | 1380 | $message = sprintf( |
@@ -1396,11 +1396,11 @@ discard block |
||
1396 | 1396 | */ |
1397 | 1397 | public function isArrayAccessible($message = null, $propertyPath = null) |
1398 | 1398 | { |
1399 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1399 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1400 | 1400 | { |
1401 | 1401 | return $this; |
1402 | 1402 | } |
1403 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
1403 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
1404 | 1404 | { |
1405 | 1405 | $message = $message ?: $this->overrideError; |
1406 | 1406 | $message = sprintf( |
@@ -1423,19 +1423,19 @@ discard block |
||
1423 | 1423 | */ |
1424 | 1424 | public function keyExists($key, $message = null, $propertyPath = null) |
1425 | 1425 | { |
1426 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1426 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1427 | 1427 | { |
1428 | 1428 | return $this; |
1429 | 1429 | } |
1430 | 1430 | $this->isArray($message, $propertyPath); |
1431 | - if ( !array_key_exists($key, $this->value) ) |
|
1431 | + if ( ! array_key_exists($key, $this->value)) |
|
1432 | 1432 | { |
1433 | 1433 | $message = $message ?: $this->overrideError; |
1434 | 1434 | $message = sprintf( |
1435 | 1435 | $message ?: 'Array does not contain an element with key "%s"', |
1436 | 1436 | $this->stringify($key) |
1437 | 1437 | ); |
1438 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, ['key' => $key]); |
|
1438 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1439 | 1439 | } |
1440 | 1440 | return $this; |
1441 | 1441 | } |
@@ -1451,21 +1451,21 @@ discard block |
||
1451 | 1451 | */ |
1452 | 1452 | public function keysExist($keys, $message = null, $propertyPath = null) |
1453 | 1453 | { |
1454 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1454 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1455 | 1455 | { |
1456 | 1456 | return $this; |
1457 | 1457 | } |
1458 | 1458 | $this->isArray($message, $propertyPath); |
1459 | - foreach ( $keys as $key ) |
|
1459 | + foreach ($keys as $key) |
|
1460 | 1460 | { |
1461 | - if ( !array_key_exists($key, $this->value) ) |
|
1461 | + if ( ! array_key_exists($key, $this->value)) |
|
1462 | 1462 | { |
1463 | 1463 | $message = $message |
1464 | 1464 | ?: sprintf( |
1465 | 1465 | 'Array does not contain an element with key "%s"', |
1466 | 1466 | $this->stringify($key) |
1467 | 1467 | ); |
1468 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, ['key' => $key]); |
|
1468 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1469 | 1469 | } |
1470 | 1470 | } |
1471 | 1471 | return $this; |
@@ -1482,19 +1482,19 @@ discard block |
||
1482 | 1482 | */ |
1483 | 1483 | public function propertyExists($key, $message = null, $propertyPath = null) |
1484 | 1484 | { |
1485 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1485 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1486 | 1486 | { |
1487 | 1487 | return $this; |
1488 | 1488 | } |
1489 | 1489 | $this->isObject($message, $propertyPath); |
1490 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1490 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1491 | 1491 | { |
1492 | 1492 | $message = $message |
1493 | 1493 | ?: sprintf( |
1494 | 1494 | 'Object does not contain a property with key "%s"', |
1495 | 1495 | $this->stringify($key) |
1496 | 1496 | ); |
1497 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, ['key' => $key]); |
|
1497 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1498 | 1498 | } |
1499 | 1499 | return $this; |
1500 | 1500 | } |
@@ -1510,22 +1510,22 @@ discard block |
||
1510 | 1510 | */ |
1511 | 1511 | public function propertiesExist(array $keys, $message = null, $propertyPath = null) |
1512 | 1512 | { |
1513 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1513 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1514 | 1514 | { |
1515 | 1515 | return $this; |
1516 | 1516 | } |
1517 | 1517 | $this->isObject($message, $propertyPath); |
1518 | - foreach ( $keys as $key ) |
|
1518 | + foreach ($keys as $key) |
|
1519 | 1519 | { |
1520 | 1520 | // Using isset to allow resolution of magically defined properties |
1521 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1521 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1522 | 1522 | { |
1523 | 1523 | $message = $message |
1524 | 1524 | ?: sprintf( |
1525 | 1525 | 'Object does not contain a property with key "%s"', |
1526 | 1526 | $this->stringify($key) |
1527 | 1527 | ); |
1528 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, ['key' => $key]); |
|
1528 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1529 | 1529 | } |
1530 | 1530 | } |
1531 | 1531 | return $this; |
@@ -1541,12 +1541,12 @@ discard block |
||
1541 | 1541 | */ |
1542 | 1542 | public function utf8($message = null, $propertyPath = null) |
1543 | 1543 | { |
1544 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1544 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1545 | 1545 | { |
1546 | 1546 | return $this; |
1547 | 1547 | } |
1548 | 1548 | $this->string($message, $propertyPath); |
1549 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1549 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
1550 | 1550 | { |
1551 | 1551 | $message = $message |
1552 | 1552 | ?: sprintf( |
@@ -1569,12 +1569,12 @@ discard block |
||
1569 | 1569 | */ |
1570 | 1570 | public function ascii($message = null, $propertyPath = null) |
1571 | 1571 | { |
1572 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1572 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1573 | 1573 | { |
1574 | 1574 | return $this; |
1575 | 1575 | } |
1576 | 1576 | $this->string($message, $propertyPath); |
1577 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1577 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
1578 | 1578 | { |
1579 | 1579 | $message = $message |
1580 | 1580 | ?: sprintf( |
@@ -1597,19 +1597,19 @@ discard block |
||
1597 | 1597 | */ |
1598 | 1598 | public function keyIsset($key, $message = null, $propertyPath = null) |
1599 | 1599 | { |
1600 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1600 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1601 | 1601 | { |
1602 | 1602 | return $this; |
1603 | 1603 | } |
1604 | 1604 | $this->isArrayAccessible($message, $propertyPath); |
1605 | - if ( !isset( $this->value[$key] ) ) |
|
1605 | + if ( ! isset($this->value[ $key ])) |
|
1606 | 1606 | { |
1607 | 1607 | $message = $message ?: $this->overrideError; |
1608 | 1608 | $message = sprintf( |
1609 | 1609 | $message ?: 'The element with key "%s" was not found', |
1610 | 1610 | $this->stringify($key) |
1611 | 1611 | ); |
1612 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, ['key' => $key]); |
|
1612 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, [ 'key' => $key ]); |
|
1613 | 1613 | } |
1614 | 1614 | return $this; |
1615 | 1615 | } |
@@ -1625,12 +1625,12 @@ discard block |
||
1625 | 1625 | */ |
1626 | 1626 | public function notEmptyKey($key, $message = null, $propertyPath = null) |
1627 | 1627 | { |
1628 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1628 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1629 | 1629 | { |
1630 | 1630 | return $this; |
1631 | 1631 | } |
1632 | 1632 | $this->keyIsset($key, $message, $propertyPath); |
1633 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1633 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1634 | 1634 | return $this; |
1635 | 1635 | } |
1636 | 1636 | |
@@ -1644,11 +1644,11 @@ discard block |
||
1644 | 1644 | */ |
1645 | 1645 | public function notBlank($message = null, $propertyPath = null) |
1646 | 1646 | { |
1647 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1647 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1648 | 1648 | { |
1649 | 1649 | return $this; |
1650 | 1650 | } |
1651 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
1651 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
1652 | 1652 | { |
1653 | 1653 | $message = $message ?: $this->overrideError; |
1654 | 1654 | $message = sprintf( |
@@ -1671,11 +1671,11 @@ discard block |
||
1671 | 1671 | */ |
1672 | 1672 | public function isInstanceOf($className, $message = null, $propertyPath = null) |
1673 | 1673 | { |
1674 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1674 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1675 | 1675 | { |
1676 | 1676 | return $this; |
1677 | 1677 | } |
1678 | - if ( !( $this->value instanceof $className ) ) |
|
1678 | + if ( ! ($this->value instanceof $className)) |
|
1679 | 1679 | { |
1680 | 1680 | $message = $message ?: $this->overrideError; |
1681 | 1681 | $message = sprintf( |
@@ -1683,7 +1683,7 @@ discard block |
||
1683 | 1683 | $this->stringify($this->value), |
1684 | 1684 | $className |
1685 | 1685 | ); |
1686 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1686 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1687 | 1687 | } |
1688 | 1688 | return $this; |
1689 | 1689 | } |
@@ -1699,11 +1699,11 @@ discard block |
||
1699 | 1699 | */ |
1700 | 1700 | public function notIsInstanceOf($className, $message = null, $propertyPath = null) |
1701 | 1701 | { |
1702 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1702 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1703 | 1703 | { |
1704 | 1704 | return $this; |
1705 | 1705 | } |
1706 | - if ( $this->value instanceof $className ) |
|
1706 | + if ($this->value instanceof $className) |
|
1707 | 1707 | { |
1708 | 1708 | $message = $message ?: $this->overrideError; |
1709 | 1709 | $message = sprintf( |
@@ -1711,7 +1711,7 @@ discard block |
||
1711 | 1711 | $this->stringify($this->value), |
1712 | 1712 | $className |
1713 | 1713 | ); |
1714 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1714 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1715 | 1715 | } |
1716 | 1716 | return $this; |
1717 | 1717 | } |
@@ -1727,11 +1727,11 @@ discard block |
||
1727 | 1727 | */ |
1728 | 1728 | public function subclassOf($className, $message = null, $propertyPath = null) |
1729 | 1729 | { |
1730 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1730 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1731 | 1731 | { |
1732 | 1732 | return $this; |
1733 | 1733 | } |
1734 | - if ( !is_subclass_of($this->value, $className) ) |
|
1734 | + if ( ! is_subclass_of($this->value, $className)) |
|
1735 | 1735 | { |
1736 | 1736 | $message = $message ?: $this->overrideError; |
1737 | 1737 | $message = sprintf( |
@@ -1739,7 +1739,7 @@ discard block |
||
1739 | 1739 | $this->stringify($this->value), |
1740 | 1740 | $className |
1741 | 1741 | ); |
1742 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, ['class' => $className]); |
|
1742 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, [ 'class' => $className ]); |
|
1743 | 1743 | } |
1744 | 1744 | return $this; |
1745 | 1745 | } |
@@ -1756,12 +1756,12 @@ discard block |
||
1756 | 1756 | */ |
1757 | 1757 | public function range($minValue, $maxValue, $message = null, $propertyPath = null) |
1758 | 1758 | { |
1759 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1759 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1760 | 1760 | { |
1761 | 1761 | return $this; |
1762 | 1762 | } |
1763 | 1763 | $this->numeric($message, $propertyPath); |
1764 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
1764 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
1765 | 1765 | { |
1766 | 1766 | $message = $message ?: $this->overrideError; |
1767 | 1767 | $message = sprintf( |
@@ -1789,12 +1789,12 @@ discard block |
||
1789 | 1789 | */ |
1790 | 1790 | public function min($minValue, $message = null, $propertyPath = null) |
1791 | 1791 | { |
1792 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1792 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1793 | 1793 | { |
1794 | 1794 | return $this; |
1795 | 1795 | } |
1796 | 1796 | $this->numeric($message, $propertyPath); |
1797 | - if ( $this->value < $minValue ) |
|
1797 | + if ($this->value < $minValue) |
|
1798 | 1798 | { |
1799 | 1799 | $message = $message ?: $this->overrideError; |
1800 | 1800 | $message = sprintf( |
@@ -1802,7 +1802,7 @@ discard block |
||
1802 | 1802 | $this->stringify($this->value), |
1803 | 1803 | $this->stringify($minValue) |
1804 | 1804 | ); |
1805 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, ['min' => $minValue]); |
|
1805 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, [ 'min' => $minValue ]); |
|
1806 | 1806 | } |
1807 | 1807 | return $this; |
1808 | 1808 | } |
@@ -1818,12 +1818,12 @@ discard block |
||
1818 | 1818 | */ |
1819 | 1819 | public function max($maxValue, $message = null, $propertyPath = null) |
1820 | 1820 | { |
1821 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1821 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1822 | 1822 | { |
1823 | 1823 | return $this; |
1824 | 1824 | } |
1825 | 1825 | $this->numeric($message, $propertyPath); |
1826 | - if ( $this->value > $maxValue ) |
|
1826 | + if ($this->value > $maxValue) |
|
1827 | 1827 | { |
1828 | 1828 | $message = $message ?: $this->overrideError; |
1829 | 1829 | $message = sprintf( |
@@ -1831,7 +1831,7 @@ discard block |
||
1831 | 1831 | $this->stringify($this->value), |
1832 | 1832 | $this->stringify($maxValue) |
1833 | 1833 | ); |
1834 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, ['max' => $maxValue]); |
|
1834 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, [ 'max' => $maxValue ]); |
|
1835 | 1835 | } |
1836 | 1836 | return $this; |
1837 | 1837 | } |
@@ -1846,13 +1846,13 @@ discard block |
||
1846 | 1846 | */ |
1847 | 1847 | public function file($message = null, $propertyPath = null) |
1848 | 1848 | { |
1849 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1849 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1850 | 1850 | { |
1851 | 1851 | return $this; |
1852 | 1852 | } |
1853 | 1853 | $this->string($message, $propertyPath); |
1854 | 1854 | $this->notEmpty($message, $propertyPath); |
1855 | - if ( !is_file($this->value) ) |
|
1855 | + if ( ! is_file($this->value)) |
|
1856 | 1856 | { |
1857 | 1857 | $message = $message ?: $this->overrideError; |
1858 | 1858 | $message = sprintf( |
@@ -1872,13 +1872,13 @@ discard block |
||
1872 | 1872 | */ |
1873 | 1873 | public function fileExists($message = null, $propertyPath = null) |
1874 | 1874 | { |
1875 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1875 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1876 | 1876 | { |
1877 | 1877 | return $this; |
1878 | 1878 | } |
1879 | 1879 | $this->string($message, $propertyPath); |
1880 | 1880 | $this->notEmpty($message, $propertyPath); |
1881 | - if ( ! file_exists($this->value) ) |
|
1881 | + if ( ! file_exists($this->value)) |
|
1882 | 1882 | { |
1883 | 1883 | $message = $message ?: $this->overrideError; |
1884 | 1884 | $message = sprintf( |
@@ -1900,12 +1900,12 @@ discard block |
||
1900 | 1900 | */ |
1901 | 1901 | public function directory($message = null, $propertyPath = null) |
1902 | 1902 | { |
1903 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1903 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1904 | 1904 | { |
1905 | 1905 | return $this; |
1906 | 1906 | } |
1907 | 1907 | $this->string($message, $propertyPath); |
1908 | - if ( !is_dir($this->value) ) |
|
1908 | + if ( ! is_dir($this->value)) |
|
1909 | 1909 | { |
1910 | 1910 | $message = $message ?: $this->overrideError; |
1911 | 1911 | $message = sprintf( |
@@ -1927,12 +1927,12 @@ discard block |
||
1927 | 1927 | */ |
1928 | 1928 | public function readable($message = null, $propertyPath = null) |
1929 | 1929 | { |
1930 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1930 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1931 | 1931 | { |
1932 | 1932 | return $this; |
1933 | 1933 | } |
1934 | 1934 | $this->string($message, $propertyPath); |
1935 | - if ( !is_readable($this->value) ) |
|
1935 | + if ( ! is_readable($this->value)) |
|
1936 | 1936 | { |
1937 | 1937 | $message = $message ?: $this->overrideError; |
1938 | 1938 | $message = sprintf( |
@@ -1954,12 +1954,12 @@ discard block |
||
1954 | 1954 | */ |
1955 | 1955 | public function writeable($message = null, $propertyPath = null) |
1956 | 1956 | { |
1957 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1957 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1958 | 1958 | { |
1959 | 1959 | return $this; |
1960 | 1960 | } |
1961 | 1961 | $this->string($message, $propertyPath); |
1962 | - if ( !is_writeable($this->value) ) |
|
1962 | + if ( ! is_writeable($this->value)) |
|
1963 | 1963 | { |
1964 | 1964 | $message = $message ?: $this->overrideError; |
1965 | 1965 | $message = sprintf( |
@@ -1982,12 +1982,12 @@ discard block |
||
1982 | 1982 | */ |
1983 | 1983 | public function email($message = null, $propertyPath = null) |
1984 | 1984 | { |
1985 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1985 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1986 | 1986 | { |
1987 | 1987 | return $this; |
1988 | 1988 | } |
1989 | 1989 | $this->string($message, $propertyPath); |
1990 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
1990 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
1991 | 1991 | { |
1992 | 1992 | $message = $message ?: $this->overrideError; |
1993 | 1993 | $message = sprintf( |
@@ -2000,7 +2000,7 @@ discard block |
||
2000 | 2000 | { |
2001 | 2001 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2002 | 2002 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
2003 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
2003 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
2004 | 2004 | { |
2005 | 2005 | $message = $message ?: $this->overrideError; |
2006 | 2006 | $message = sprintf( |
@@ -2021,7 +2021,7 @@ discard block |
||
2021 | 2021 | */ |
2022 | 2022 | public function emailPrefix($message = null, $propertyPath = null) |
2023 | 2023 | { |
2024 | - $this->value($this->value . '@example.com'); |
|
2024 | + $this->value($this->value.'@example.com'); |
|
2025 | 2025 | return $this->email($message, $propertyPath); |
2026 | 2026 | } |
2027 | 2027 | |
@@ -2041,12 +2041,12 @@ discard block |
||
2041 | 2041 | */ |
2042 | 2042 | public function url($message = null, $propertyPath = null) |
2043 | 2043 | { |
2044 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2044 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2045 | 2045 | { |
2046 | 2046 | return $this; |
2047 | 2047 | } |
2048 | 2048 | $this->string($message, $propertyPath); |
2049 | - $protocols = ['http', 'https']; |
|
2049 | + $protocols = [ 'http', 'https' ]; |
|
2050 | 2050 | $pattern = '~^ |
2051 | 2051 | (%s):// # protocol |
2052 | 2052 | ( |
@@ -2061,8 +2061,8 @@ discard block |
||
2061 | 2061 | (:[0-9]+)? # a port (optional) |
2062 | 2062 | (/?|/\S+) # a /, nothing or a / with something |
2063 | 2063 | $~ixu'; |
2064 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2065 | - if ( !preg_match($pattern, $this->value) ) |
|
2064 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2065 | + if ( ! preg_match($pattern, $this->value)) |
|
2066 | 2066 | { |
2067 | 2067 | $message = $message ?: $this->overrideError; |
2068 | 2068 | $message = sprintf( |
@@ -2087,13 +2087,13 @@ discard block |
||
2087 | 2087 | */ |
2088 | 2088 | public function domainName($message = null, $propertyPath = null) |
2089 | 2089 | { |
2090 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2090 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2091 | 2091 | { |
2092 | 2092 | return $this; |
2093 | 2093 | } |
2094 | 2094 | $this->string($message, $propertyPath); |
2095 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2096 | - if ( ! preg_match($pattern, $this->value) ) |
|
2095 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2096 | + if ( ! preg_match($pattern, $this->value)) |
|
2097 | 2097 | { |
2098 | 2098 | $message = $message ?: $this->overrideError; |
2099 | 2099 | $message = sprintf( |
@@ -2115,7 +2115,7 @@ discard block |
||
2115 | 2115 | */ |
2116 | 2116 | public function ausMobile($message = null, $propertyPath = null) |
2117 | 2117 | { |
2118 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2118 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2119 | 2119 | { |
2120 | 2120 | return $this; |
2121 | 2121 | } |
@@ -2123,7 +2123,7 @@ discard block |
||
2123 | 2123 | { |
2124 | 2124 | $this->regex('/^04[0-9]{8})$/', $message, $propertyPath); |
2125 | 2125 | } |
2126 | - catch ( AssertionFailedException $e ) |
|
2126 | + catch (AssertionFailedException $e) |
|
2127 | 2127 | { |
2128 | 2128 | $message = $message ?: $this->overrideError; |
2129 | 2129 | $message = sprintf( |
@@ -2146,7 +2146,7 @@ discard block |
||
2146 | 2146 | */ |
2147 | 2147 | public function alnum($message = null, $propertyPath = null) |
2148 | 2148 | { |
2149 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2149 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2150 | 2150 | { |
2151 | 2151 | return $this; |
2152 | 2152 | } |
@@ -2177,11 +2177,11 @@ discard block |
||
2177 | 2177 | */ |
2178 | 2178 | public function true($message = null, $propertyPath = null) |
2179 | 2179 | { |
2180 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2180 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2181 | 2181 | { |
2182 | 2182 | return $this; |
2183 | 2183 | } |
2184 | - if ( $this->value !== true ) |
|
2184 | + if ($this->value !== true) |
|
2185 | 2185 | { |
2186 | 2186 | $message = $message ?: $this->overrideError; |
2187 | 2187 | $message = sprintf( |
@@ -2204,11 +2204,11 @@ discard block |
||
2204 | 2204 | */ |
2205 | 2205 | public function truthy($message = null, $propertyPath = null) |
2206 | 2206 | { |
2207 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2207 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2208 | 2208 | { |
2209 | 2209 | return $this; |
2210 | 2210 | } |
2211 | - if ( ! $this->value ) |
|
2211 | + if ( ! $this->value) |
|
2212 | 2212 | { |
2213 | 2213 | $message = $message ?: $this->overrideError; |
2214 | 2214 | $message = sprintf( |
@@ -2230,11 +2230,11 @@ discard block |
||
2230 | 2230 | */ |
2231 | 2231 | public function false($message = null, $propertyPath = null) |
2232 | 2232 | { |
2233 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2233 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2234 | 2234 | { |
2235 | 2235 | return $this; |
2236 | 2236 | } |
2237 | - if ( $this->value !== false ) |
|
2237 | + if ($this->value !== false) |
|
2238 | 2238 | { |
2239 | 2239 | $message = $message ?: $this->overrideError; |
2240 | 2240 | $message = sprintf( |
@@ -2256,11 +2256,11 @@ discard block |
||
2256 | 2256 | */ |
2257 | 2257 | public function notFalse($message = null, $propertyPath = null) |
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 | - if ( $this->value === false ) |
|
2263 | + if ($this->value === false) |
|
2264 | 2264 | { |
2265 | 2265 | $message = $message ?: $this->overrideError; |
2266 | 2266 | $message = sprintf( |
@@ -2282,11 +2282,11 @@ discard block |
||
2282 | 2282 | */ |
2283 | 2283 | public function classExists($message = null, $propertyPath = null) |
2284 | 2284 | { |
2285 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2285 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2286 | 2286 | { |
2287 | 2287 | return $this; |
2288 | 2288 | } |
2289 | - if ( !class_exists($this->value) ) |
|
2289 | + if ( ! class_exists($this->value)) |
|
2290 | 2290 | { |
2291 | 2291 | $message = $message ?: $this->overrideError; |
2292 | 2292 | $message = sprintf( |
@@ -2309,12 +2309,12 @@ discard block |
||
2309 | 2309 | */ |
2310 | 2310 | public function implementsInterface($interfaceName, $message = null, $propertyPath = null) |
2311 | 2311 | { |
2312 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2312 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2313 | 2313 | { |
2314 | 2314 | return $this; |
2315 | 2315 | } |
2316 | 2316 | $reflection = new \ReflectionClass($this->value); |
2317 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
2317 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
2318 | 2318 | { |
2319 | 2319 | $message = $message ?: $this->overrideError; |
2320 | 2320 | $message = sprintf( |
@@ -2322,7 +2322,7 @@ discard block |
||
2322 | 2322 | $this->stringify($this->value), |
2323 | 2323 | $this->stringify($interfaceName) |
2324 | 2324 | ); |
2325 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, ['interface' => $interfaceName]); |
|
2325 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, [ 'interface' => $interfaceName ]); |
|
2326 | 2326 | } |
2327 | 2327 | return $this; |
2328 | 2328 | } |
@@ -2343,11 +2343,11 @@ discard block |
||
2343 | 2343 | */ |
2344 | 2344 | public function isJsonString($message = null, $propertyPath = null) |
2345 | 2345 | { |
2346 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2346 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2347 | 2347 | { |
2348 | 2348 | return $this; |
2349 | 2349 | } |
2350 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
2350 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
2351 | 2351 | { |
2352 | 2352 | $message = $message ?: $this->overrideError; |
2353 | 2353 | $message = sprintf( |
@@ -2371,16 +2371,16 @@ discard block |
||
2371 | 2371 | */ |
2372 | 2372 | public function uuid($message = null, $propertyPath = null) |
2373 | 2373 | { |
2374 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2374 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2375 | 2375 | { |
2376 | 2376 | return $this; |
2377 | 2377 | } |
2378 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
2379 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
2378 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
2379 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
2380 | 2380 | { |
2381 | 2381 | return $this; |
2382 | 2382 | } |
2383 | - 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) ) |
|
2383 | + 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)) |
|
2384 | 2384 | { |
2385 | 2385 | $message = $message ?: $this->overrideError; |
2386 | 2386 | $message = sprintf( |
@@ -2403,11 +2403,11 @@ discard block |
||
2403 | 2403 | */ |
2404 | 2404 | public function count($count, $message = null, $propertyPath = null) |
2405 | 2405 | { |
2406 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2406 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2407 | 2407 | { |
2408 | 2408 | return $this; |
2409 | 2409 | } |
2410 | - if ( $count !== count($this->value) ) |
|
2410 | + if ($count !== count($this->value)) |
|
2411 | 2411 | { |
2412 | 2412 | $message = $message ?: $this->overrideError; |
2413 | 2413 | $message = sprintf( |
@@ -2415,7 +2415,7 @@ discard block |
||
2415 | 2415 | $this->stringify($this->value), |
2416 | 2416 | $this->stringify($count) |
2417 | 2417 | ); |
2418 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, ['count' => $count]); |
|
2418 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, [ 'count' => $count ]); |
|
2419 | 2419 | } |
2420 | 2420 | return $this; |
2421 | 2421 | } |
@@ -2428,24 +2428,24 @@ discard block |
||
2428 | 2428 | */ |
2429 | 2429 | protected function doAllOrNullOr($func, $args) |
2430 | 2430 | { |
2431 | - if ( $this->nullOr && is_null($this->value) ) |
|
2431 | + if ($this->nullOr && is_null($this->value)) |
|
2432 | 2432 | { |
2433 | 2433 | return true; |
2434 | 2434 | } |
2435 | - if ( $this->emptyOr && empty($this->value) ) |
|
2435 | + if ($this->emptyOr && empty($this->value)) |
|
2436 | 2436 | { |
2437 | 2437 | return true; |
2438 | 2438 | } |
2439 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
2439 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
2440 | 2440 | { |
2441 | - foreach ( $this->value as $idx => $value ) |
|
2441 | + foreach ($this->value as $idx => $value) |
|
2442 | 2442 | { |
2443 | 2443 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
2444 | - call_user_func_array([$object, $func], $args); |
|
2444 | + call_user_func_array([ $object, $func ], $args); |
|
2445 | 2445 | } |
2446 | 2446 | return true; |
2447 | 2447 | } |
2448 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
2448 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
2449 | 2449 | } |
2450 | 2450 | |
2451 | 2451 | /** |
@@ -2458,12 +2458,12 @@ discard block |
||
2458 | 2458 | */ |
2459 | 2459 | public function choicesNotEmpty(array $choices, $message = null, $propertyPath = null) |
2460 | 2460 | { |
2461 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2461 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2462 | 2462 | { |
2463 | 2463 | return $this; |
2464 | 2464 | } |
2465 | 2465 | $this->notEmpty($message, $propertyPath); |
2466 | - foreach ( $choices as $choice ) |
|
2466 | + foreach ($choices as $choice) |
|
2467 | 2467 | { |
2468 | 2468 | $this->notEmptyKey($choice, $message, $propertyPath); |
2469 | 2469 | } |
@@ -2481,12 +2481,12 @@ discard block |
||
2481 | 2481 | */ |
2482 | 2482 | public function methodExists($object, $message = null, $propertyPath = null) |
2483 | 2483 | { |
2484 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2484 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2485 | 2485 | { |
2486 | 2486 | return $this; |
2487 | 2487 | } |
2488 | 2488 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath); |
2489 | - if ( !method_exists($object, $this->value) ) |
|
2489 | + if ( ! method_exists($object, $this->value)) |
|
2490 | 2490 | { |
2491 | 2491 | $message = $message ?: $this->overrideError; |
2492 | 2492 | $message = sprintf( |
@@ -2508,11 +2508,11 @@ discard block |
||
2508 | 2508 | */ |
2509 | 2509 | public function isObject($message = null, $propertyPath = null) |
2510 | 2510 | { |
2511 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2511 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2512 | 2512 | { |
2513 | 2513 | return $this; |
2514 | 2514 | } |
2515 | - if ( !is_object($this->value) ) |
|
2515 | + if ( ! is_object($this->value)) |
|
2516 | 2516 | { |
2517 | 2517 | $message = $message ?: $this->overrideError; |
2518 | 2518 | $message = sprintf( |
@@ -2532,32 +2532,32 @@ discard block |
||
2532 | 2532 | */ |
2533 | 2533 | private function stringify($value) |
2534 | 2534 | { |
2535 | - if ( is_bool($value) ) |
|
2535 | + if (is_bool($value)) |
|
2536 | 2536 | { |
2537 | 2537 | return $value ? '<TRUE>' : '<FALSE>'; |
2538 | 2538 | } |
2539 | - if ( is_scalar($value) ) |
|
2539 | + if (is_scalar($value)) |
|
2540 | 2540 | { |
2541 | 2541 | $val = (string)$value; |
2542 | - if ( strlen($val) > 100 ) |
|
2542 | + if (strlen($val) > 100) |
|
2543 | 2543 | { |
2544 | - $val = substr($val, 0, 97) . '...'; |
|
2544 | + $val = substr($val, 0, 97).'...'; |
|
2545 | 2545 | } |
2546 | 2546 | return $val; |
2547 | 2547 | } |
2548 | - if ( is_array($value) ) |
|
2548 | + if (is_array($value)) |
|
2549 | 2549 | { |
2550 | 2550 | return '<ARRAY>'; |
2551 | 2551 | } |
2552 | - if ( is_object($value) ) |
|
2552 | + if (is_object($value)) |
|
2553 | 2553 | { |
2554 | 2554 | return get_class($value); |
2555 | 2555 | } |
2556 | - if ( is_resource($value) ) |
|
2556 | + if (is_resource($value)) |
|
2557 | 2557 | { |
2558 | 2558 | return '<RESOURCE>'; |
2559 | 2559 | } |
2560 | - if ( $value === null ) |
|
2560 | + if ($value === null) |
|
2561 | 2561 | { |
2562 | 2562 | return '<NULL>'; |
2563 | 2563 | } |
@@ -1995,8 +1995,7 @@ discard block |
||
1995 | 1995 | $this->stringify($this->value) |
1996 | 1996 | ); |
1997 | 1997 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_EMAIL, $propertyPath); |
1998 | - } |
|
1999 | - else |
|
1998 | + } else |
|
2000 | 1999 | { |
2001 | 2000 | $host = substr($this->value, strpos($this->value, '@') + 1); |
2002 | 2001 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
@@ -2122,8 +2121,7 @@ discard block |
||
2122 | 2121 | try |
2123 | 2122 | { |
2124 | 2123 | $this->regex('/^04[0-9]{8})$/', $message, $propertyPath); |
2125 | - } |
|
2126 | - catch ( AssertionFailedException $e ) |
|
2124 | + } catch ( AssertionFailedException $e ) |
|
2127 | 2125 | { |
2128 | 2126 | $message = $message ?: $this->overrideError; |
2129 | 2127 | $message = sprintf( |
@@ -2153,8 +2151,7 @@ discard block |
||
2153 | 2151 | try |
2154 | 2152 | { |
2155 | 2153 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); |
2156 | - } |
|
2157 | - catch (AssertionFailedException $e) |
|
2154 | + } catch (AssertionFailedException $e) |
|
2158 | 2155 | { |
2159 | 2156 | $message = $message ?: $this->overrideError; |
2160 | 2157 | $message = sprintf( |