@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | /** |
| 535 | 535 | * Assert that value is not equal to a provided value (using == ). |
| 536 | 536 | * |
| 537 | - * @param mixed $value2 |
|
| 537 | + * @param string $value2 |
|
| 538 | 538 | * @param string $message |
| 539 | 539 | * @param string $fieldName |
| 540 | 540 | * @return Assert |
@@ -1408,7 +1408,7 @@ discard block |
||
| 1408 | 1408 | /** |
| 1409 | 1409 | * Alias of {@see choice()} |
| 1410 | 1410 | * |
| 1411 | - * @param array $choices |
|
| 1411 | + * @param integer[] $choices |
|
| 1412 | 1412 | * @param string $message |
| 1413 | 1413 | * @param string $fieldName |
| 1414 | 1414 | * @return Assert |
@@ -1585,7 +1585,7 @@ discard block |
||
| 1585 | 1585 | /** |
| 1586 | 1586 | * Assert that key exists in the values array. |
| 1587 | 1587 | * |
| 1588 | - * @param string|integer $key |
|
| 1588 | + * @param string $key |
|
| 1589 | 1589 | * @param string $message |
| 1590 | 1590 | * @param string $fieldName |
| 1591 | 1591 | * @return Assert |
@@ -2728,7 +2728,7 @@ discard block |
||
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | 2730 | /** |
| 2731 | - * @param $func |
|
| 2731 | + * @param string $func |
|
| 2732 | 2732 | * @param $args |
| 2733 | 2733 | * @return bool |
| 2734 | 2734 | * @throws AssertionFailedException |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * |
| 137 | 137 | * @var string |
| 138 | 138 | */ |
| 139 | - protected $exceptionClass = AssertionFailedException::class; |
|
| 139 | + protected $exceptionClass = AssertionFailedException::class; |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @param mixed $value |
@@ -152,16 +152,16 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public static function runValidators(array $validators) : array |
| 154 | 154 | { |
| 155 | - $errors = []; |
|
| 156 | - foreach ( $validators as $fieldName => $validator ) |
|
| 155 | + $errors = [ ]; |
|
| 156 | + foreach ($validators as $fieldName => $validator) |
|
| 157 | 157 | { |
| 158 | 158 | try |
| 159 | 159 | { |
| 160 | 160 | $validator->__invoke(); |
| 161 | 161 | } |
| 162 | - catch ( AssertionFailedException $e ) |
|
| 162 | + catch (AssertionFailedException $e) |
|
| 163 | 163 | { |
| 164 | - $errors[$fieldName] = $e->getMessage(); |
|
| 164 | + $errors[ $fieldName ] = $e->getMessage(); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @param string $level |
| 177 | 177 | * @return Assert |
| 178 | 178 | */ |
| 179 | - public static function that($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) : Assert |
|
| 179 | + public static function that($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) : Assert |
|
| 180 | 180 | { |
| 181 | 181 | $assert = new static($value); |
| 182 | - if ( $fieldName ) |
|
| 182 | + if ($fieldName) |
|
| 183 | 183 | { |
| 184 | 184 | $assert->fieldName($fieldName); |
| 185 | 185 | } |
| 186 | - if ( $code ) |
|
| 186 | + if ($code) |
|
| 187 | 187 | { |
| 188 | 188 | $assert->code($code); |
| 189 | 189 | } |
| 190 | - if ( $error ) |
|
| 190 | + if ($error) |
|
| 191 | 191 | { |
| 192 | 192 | $assert->error($error); |
| 193 | 193 | } |
| 194 | - if ( $level ) |
|
| 194 | + if ($level) |
|
| 195 | 195 | { |
| 196 | 196 | $assert->level($level); |
| 197 | 197 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param string $level |
| 271 | 271 | * @return AssertionFailedException |
| 272 | 272 | */ |
| 273 | - protected function createException(string $message, int $code, string $fieldName, array $constraints=[], string $level='') : AssertionFailedException |
|
| 273 | + protected function createException(string $message, int $code, string $fieldName, array $constraints = [ ], string $level = '') : AssertionFailedException |
|
| 274 | 274 | { |
| 275 | 275 | $exceptionClass = $this->exceptionClass; |
| 276 | 276 | $fieldName = empty($fieldName) ? $this->fieldName : $fieldName; |
@@ -372,13 +372,13 @@ discard block |
||
| 372 | 372 | * @return Assert |
| 373 | 373 | * @throws AssertionFailedException |
| 374 | 374 | */ |
| 375 | - public function eq($value2, string $message='', string $fieldName='') : Assert |
|
| 375 | + public function eq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 376 | 376 | { |
| 377 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 377 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 378 | 378 | { |
| 379 | 379 | return $this; |
| 380 | 380 | } |
| 381 | - if ( $this->value != $value2 ) |
|
| 381 | + if ($this->value != $value2) |
|
| 382 | 382 | { |
| 383 | 383 | $message = $message ?: $this->overrideError; |
| 384 | 384 | $message = sprintf( |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $this->stringify($value2) |
| 388 | 388 | ); |
| 389 | 389 | |
| 390 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 390 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | return $this; |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | * @return Assert |
| 403 | 403 | * @throws AssertionFailedException |
| 404 | 404 | */ |
| 405 | - public function greaterThan($value2, string $message='', string $fieldName='') : Assert |
|
| 405 | + public function greaterThan($value2, string $message = '', string $fieldName = '') : Assert |
|
| 406 | 406 | { |
| 407 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 407 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 408 | 408 | { |
| 409 | 409 | return $this; |
| 410 | 410 | } |
| 411 | - if ( ! ( $this->value > $value2 ) ) |
|
| 411 | + if ( ! ($this->value > $value2)) |
|
| 412 | 412 | { |
| 413 | 413 | $message = $message ?: $this->overrideError; |
| 414 | 414 | $message = sprintf( |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $this->stringify($value2) |
| 418 | 418 | ); |
| 419 | 419 | |
| 420 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 420 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | return $this; |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | * @return Assert |
| 433 | 433 | * @throws AssertionFailedException |
| 434 | 434 | */ |
| 435 | - public function greaterThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
| 435 | + public function greaterThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 436 | 436 | { |
| 437 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 437 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 438 | 438 | { |
| 439 | 439 | return $this; |
| 440 | 440 | } |
| 441 | - if ( ! ( $this->value >= $value2 ) ) |
|
| 441 | + if ( ! ($this->value >= $value2)) |
|
| 442 | 442 | { |
| 443 | 443 | $message = $message ?: $this->overrideError; |
| 444 | 444 | $message = sprintf( |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | $this->stringify($value2) |
| 448 | 448 | ); |
| 449 | 449 | |
| 450 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 450 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | return $this; |
@@ -462,13 +462,13 @@ discard block |
||
| 462 | 462 | * @return Assert |
| 463 | 463 | * @throws AssertionFailedException |
| 464 | 464 | */ |
| 465 | - public function lessThan($value2, string $message='', string $fieldName='') : Assert |
|
| 465 | + public function lessThan($value2, string $message = '', string $fieldName = '') : Assert |
|
| 466 | 466 | { |
| 467 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 467 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 468 | 468 | { |
| 469 | 469 | return $this; |
| 470 | 470 | } |
| 471 | - if ( ! ( $this->value < $value2 ) ) |
|
| 471 | + if ( ! ($this->value < $value2)) |
|
| 472 | 472 | { |
| 473 | 473 | $message = $message ?: $this->overrideError; |
| 474 | 474 | $message = sprintf( |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | $this->stringify($value2) |
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, ['expected' => $value2]); |
|
| 480 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, [ 'expected' => $value2 ]); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | return $this; |
@@ -492,13 +492,13 @@ discard block |
||
| 492 | 492 | * @return Assert |
| 493 | 493 | * @throws AssertionFailedException |
| 494 | 494 | */ |
| 495 | - public function lessThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
| 495 | + public function lessThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 496 | 496 | { |
| 497 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 497 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 498 | 498 | { |
| 499 | 499 | return $this; |
| 500 | 500 | } |
| 501 | - if ( ! ( $this->value <= $value2 ) ) |
|
| 501 | + if ( ! ($this->value <= $value2)) |
|
| 502 | 502 | { |
| 503 | 503 | $message = $message ?: $this->overrideError; |
| 504 | 504 | $message = sprintf( |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | $this->stringify($value2) |
| 508 | 508 | ); |
| 509 | 509 | |
| 510 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, ['expected' => $value2]); |
|
| 510 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | return $this; |
@@ -522,13 +522,13 @@ discard block |
||
| 522 | 522 | * @return Assert |
| 523 | 523 | * @throws AssertionFailedException |
| 524 | 524 | */ |
| 525 | - public function same($value2, string $message='', string $fieldName='') : Assert |
|
| 525 | + public function same($value2, string $message = '', string $fieldName = '') : Assert |
|
| 526 | 526 | { |
| 527 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 527 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 528 | 528 | { |
| 529 | 529 | return $this; |
| 530 | 530 | } |
| 531 | - if ( $this->value !== $value2 ) |
|
| 531 | + if ($this->value !== $value2) |
|
| 532 | 532 | { |
| 533 | 533 | $message = $message ?: $this->overrideError; |
| 534 | 534 | $message = sprintf( |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | $this->stringify($value2) |
| 538 | 538 | ); |
| 539 | 539 | |
| 540 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, ['expected' => $value2]); |
|
| 540 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | return $this; |
@@ -552,13 +552,13 @@ discard block |
||
| 552 | 552 | * @return Assert |
| 553 | 553 | * @throws AssertionFailedException |
| 554 | 554 | */ |
| 555 | - public function notEq($value2, string $message='', string $fieldName='') : Assert |
|
| 555 | + public function notEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 556 | 556 | { |
| 557 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 557 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 558 | 558 | { |
| 559 | 559 | return $this; |
| 560 | 560 | } |
| 561 | - if ( $this->value == $value2 ) |
|
| 561 | + if ($this->value == $value2) |
|
| 562 | 562 | { |
| 563 | 563 | $message = $message ?: $this->overrideError; |
| 564 | 564 | $message = sprintf( |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | $this->stringify($value2) |
| 568 | 568 | ); |
| 569 | 569 | |
| 570 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, ['expected' => $value2]); |
|
| 570 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | return $this; |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | * @return Assert |
| 582 | 582 | * @throws AssertionFailedException |
| 583 | 583 | */ |
| 584 | - public function isCallable(string $message='', string $fieldName='') : Assert |
|
| 584 | + public function isCallable(string $message = '', string $fieldName = '') : Assert |
|
| 585 | 585 | { |
| 586 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 586 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 587 | 587 | { |
| 588 | 588 | return $this; |
| 589 | 589 | } |
| 590 | - if ( !is_callable($this->value) ) |
|
| 590 | + if ( ! is_callable($this->value)) |
|
| 591 | 591 | { |
| 592 | 592 | $message = $message ?: $this->overrideError; |
| 593 | 593 | $message = sprintf( |
@@ -610,13 +610,13 @@ discard block |
||
| 610 | 610 | * @return Assert |
| 611 | 611 | * @throws AssertionFailedException |
| 612 | 612 | */ |
| 613 | - public function notSame($value2, string $message='', string $fieldName='') : Assert |
|
| 613 | + public function notSame($value2, string $message = '', string $fieldName = '') : Assert |
|
| 614 | 614 | { |
| 615 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 615 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 616 | 616 | { |
| 617 | 617 | return $this; |
| 618 | 618 | } |
| 619 | - if ( $this->value === $value2 ) |
|
| 619 | + if ($this->value === $value2) |
|
| 620 | 620 | { |
| 621 | 621 | $message = $message ?: $this->overrideError; |
| 622 | 622 | $message = sprintf( |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | $this->stringify($value2) |
| 626 | 626 | ); |
| 627 | 627 | |
| 628 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, ['expected' => $value2]); |
|
| 628 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | return $this; |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | * @return Assert |
| 640 | 640 | * @throws AssertionFailedException |
| 641 | 641 | */ |
| 642 | - public function id(string $message='', string $fieldName='') : Assert |
|
| 642 | + public function id(string $message = '', string $fieldName = '') : Assert |
|
| 643 | 643 | { |
| 644 | 644 | $message = $message ?: $this->overrideError; |
| 645 | 645 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @return Assert |
| 655 | 655 | * @throws AssertionFailedException |
| 656 | 656 | */ |
| 657 | - public function unsignedInt(string $message='', string $fieldName='') : Assert |
|
| 657 | + public function unsignedInt(string $message = '', string $fieldName = '') : Assert |
|
| 658 | 658 | { |
| 659 | 659 | $message = $message ?: $this->overrideError; |
| 660 | 660 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * @return Assert |
| 671 | 671 | * @throws AssertionFailedException |
| 672 | 672 | */ |
| 673 | - public function flag(string $message='', string $fieldName='') : Assert |
|
| 673 | + public function flag(string $message = '', string $fieldName = '') : Assert |
|
| 674 | 674 | { |
| 675 | 675 | $message = $message ?: $this->overrideError; |
| 676 | 676 | $message = $message ?: 'Value "%s" is not a 0 or 1.'; |
@@ -686,12 +686,12 @@ discard block |
||
| 686 | 686 | * @return Assert |
| 687 | 687 | * @throws AssertionFailedException |
| 688 | 688 | */ |
| 689 | - public function status(string $message='', string $fieldName='') : Assert |
|
| 689 | + public function status(string $message = '', string $fieldName = '') : Assert |
|
| 690 | 690 | { |
| 691 | 691 | $message = $message ?: $this->overrideError; |
| 692 | 692 | $message = $message ?: 'Value "%s" is not a valid status.'; |
| 693 | 693 | |
| 694 | - return $this->integer($message, $fieldName)->inArray([-1, 0, 1]); |
|
| 694 | + return $this->integer($message, $fieldName)->inArray([-1, 0, 1 ]); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @return Assert |
| 703 | 703 | * @throws AssertionFailedException |
| 704 | 704 | */ |
| 705 | - public function nullOrId(string $message='', string $fieldName='') : Assert |
|
| 705 | + public function nullOrId(string $message = '', string $fieldName = '') : Assert |
|
| 706 | 706 | { |
| 707 | 707 | return $this->nullOr()->id($message, $fieldName); |
| 708 | 708 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @return Assert |
| 716 | 716 | * @throws AssertionFailedException |
| 717 | 717 | */ |
| 718 | - public function allIds(string $message='', string $fieldName='') : Assert |
|
| 718 | + public function allIds(string $message = '', string $fieldName = '') : Assert |
|
| 719 | 719 | { |
| 720 | 720 | return $this->all()->id($message, $fieldName); |
| 721 | 721 | } |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @return Assert |
| 729 | 729 | * @throws AssertionFailedException |
| 730 | 730 | */ |
| 731 | - public function int(string $message='', string $fieldName='') : Assert |
|
| 731 | + public function int(string $message = '', string $fieldName = '') : Assert |
|
| 732 | 732 | { |
| 733 | 733 | return $this->integer($message, $fieldName); |
| 734 | 734 | } |
@@ -741,13 +741,13 @@ discard block |
||
| 741 | 741 | * @return Assert |
| 742 | 742 | * @throws AssertionFailedException |
| 743 | 743 | */ |
| 744 | - public function integer(string $message='', string $fieldName='') : Assert |
|
| 744 | + public function integer(string $message = '', string $fieldName = '') : Assert |
|
| 745 | 745 | { |
| 746 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 746 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 747 | 747 | { |
| 748 | 748 | return $this; |
| 749 | 749 | } |
| 750 | - if ( !is_int($this->value) ) |
|
| 750 | + if ( ! is_int($this->value)) |
|
| 751 | 751 | { |
| 752 | 752 | $message = $message ?: $this->overrideError; |
| 753 | 753 | $message = sprintf( |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | * @return Assert |
| 770 | 770 | * @throws AssertionFailedException |
| 771 | 771 | */ |
| 772 | - public function float(string $message='', string $fieldName='') : Assert |
|
| 772 | + public function float(string $message = '', string $fieldName = '') : Assert |
|
| 773 | 773 | { |
| 774 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 774 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 775 | 775 | { |
| 776 | 776 | return $this; |
| 777 | 777 | } |
| 778 | - if ( ! is_float($this->value) ) |
|
| 778 | + if ( ! is_float($this->value)) |
|
| 779 | 779 | { |
| 780 | 780 | $message = $message ?: $this->overrideError; |
| 781 | 781 | $message = sprintf( |
@@ -797,13 +797,13 @@ discard block |
||
| 797 | 797 | * @return Assert |
| 798 | 798 | * @throws AssertionFailedException |
| 799 | 799 | */ |
| 800 | - public function digit(string $message='', string $fieldName='') : Assert |
|
| 800 | + public function digit(string $message = '', string $fieldName = '') : Assert |
|
| 801 | 801 | { |
| 802 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 802 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 803 | 803 | { |
| 804 | 804 | return $this; |
| 805 | 805 | } |
| 806 | - if ( ! ctype_digit((string)$this->value) ) |
|
| 806 | + if ( ! ctype_digit((string)$this->value)) |
|
| 807 | 807 | { |
| 808 | 808 | $message = $message ?: $this->overrideError; |
| 809 | 809 | $message = sprintf( |
@@ -825,18 +825,18 @@ discard block |
||
| 825 | 825 | * @return Assert |
| 826 | 826 | * @throws AssertionFailedException |
| 827 | 827 | */ |
| 828 | - public function date(string $message='', string $fieldName='') : Assert |
|
| 828 | + public function date(string $message = '', string $fieldName = '') : Assert |
|
| 829 | 829 | { |
| 830 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 830 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 831 | 831 | { |
| 832 | 832 | return $this; |
| 833 | 833 | } |
| 834 | 834 | $this->notEmpty($message, $fieldName); |
| 835 | - if ( $this->value instanceof \DateTime ) |
|
| 835 | + if ($this->value instanceof \DateTime) |
|
| 836 | 836 | { |
| 837 | 837 | return $this; |
| 838 | 838 | } |
| 839 | - if ( strtotime($this->value) === false ) |
|
| 839 | + if (strtotime($this->value) === false) |
|
| 840 | 840 | { |
| 841 | 841 | $message = $message ?: $this->overrideError; |
| 842 | 842 | $message = sprintf( |
@@ -857,14 +857,14 @@ discard block |
||
| 857 | 857 | * @return $this |
| 858 | 858 | * @throws AssertionFailedException |
| 859 | 859 | */ |
| 860 | - public function after($afterDate, string $message='', string $fieldName='') |
|
| 860 | + public function after($afterDate, string $message = '', string $fieldName = '') |
|
| 861 | 861 | { |
| 862 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 862 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 863 | 863 | { |
| 864 | 864 | return $this; |
| 865 | 865 | } |
| 866 | 866 | $this->notEmpty($message, $fieldName); |
| 867 | - if ( strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate) ) |
|
| 867 | + if (strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate)) |
|
| 868 | 868 | { |
| 869 | 869 | $message = $message ?: $this->overrideError; |
| 870 | 870 | $message = sprintf( |
@@ -886,13 +886,13 @@ discard block |
||
| 886 | 886 | * @return Assert |
| 887 | 887 | * @throws AssertionFailedException |
| 888 | 888 | */ |
| 889 | - public function integerish(string $message='', string $fieldName='') : Assert |
|
| 889 | + public function integerish(string $message = '', string $fieldName = '') : Assert |
|
| 890 | 890 | { |
| 891 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 891 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 892 | 892 | { |
| 893 | 893 | return $this; |
| 894 | 894 | } |
| 895 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
| 895 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
| 896 | 896 | { |
| 897 | 897 | $message = $message ?: $this->overrideError; |
| 898 | 898 | $message = sprintf( |
@@ -914,13 +914,13 @@ discard block |
||
| 914 | 914 | * @return Assert |
| 915 | 915 | * @throws AssertionFailedException |
| 916 | 916 | */ |
| 917 | - public function boolean(string $message='', string $fieldName='') : Assert |
|
| 917 | + public function boolean(string $message = '', string $fieldName = '') : Assert |
|
| 918 | 918 | { |
| 919 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 919 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 920 | 920 | { |
| 921 | 921 | return $this; |
| 922 | 922 | } |
| 923 | - if ( ! is_bool($this->value) ) |
|
| 923 | + if ( ! is_bool($this->value)) |
|
| 924 | 924 | { |
| 925 | 925 | $message = $message ?: $this->overrideError; |
| 926 | 926 | $message = sprintf( |
@@ -942,13 +942,13 @@ discard block |
||
| 942 | 942 | * @return Assert |
| 943 | 943 | * @throws AssertionFailedException |
| 944 | 944 | */ |
| 945 | - public function scalar(string $message='', string $fieldName='') : Assert |
|
| 945 | + public function scalar(string $message = '', string $fieldName = '') : Assert |
|
| 946 | 946 | { |
| 947 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 947 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 948 | 948 | { |
| 949 | 949 | return $this; |
| 950 | 950 | } |
| 951 | - if ( ! is_scalar($this->value) ) |
|
| 951 | + if ( ! is_scalar($this->value)) |
|
| 952 | 952 | { |
| 953 | 953 | $message = $message ?: $this->overrideError; |
| 954 | 954 | $message = sprintf( |
@@ -970,13 +970,13 @@ discard block |
||
| 970 | 970 | * @return Assert |
| 971 | 971 | * @throws AssertionFailedException |
| 972 | 972 | */ |
| 973 | - public function notEmpty(string $message='', string $fieldName='') : Assert |
|
| 973 | + public function notEmpty(string $message = '', string $fieldName = '') : Assert |
|
| 974 | 974 | { |
| 975 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 975 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 976 | 976 | { |
| 977 | 977 | return $this; |
| 978 | 978 | } |
| 979 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
| 979 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
| 980 | 980 | { |
| 981 | 981 | $message = $message ?: $this->overrideError; |
| 982 | 982 | $message = sprintf( |
@@ -998,13 +998,13 @@ discard block |
||
| 998 | 998 | * @return Assert |
| 999 | 999 | * @throws AssertionFailedException |
| 1000 | 1000 | */ |
| 1001 | - public function noContent(string $message='', string $fieldName='') : Assert |
|
| 1001 | + public function noContent(string $message = '', string $fieldName = '') : Assert |
|
| 1002 | 1002 | { |
| 1003 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1003 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1004 | 1004 | { |
| 1005 | 1005 | return $this; |
| 1006 | 1006 | } |
| 1007 | - if ( !empty( $this->value ) ) |
|
| 1007 | + if ( ! empty($this->value)) |
|
| 1008 | 1008 | { |
| 1009 | 1009 | $message = $message ?: $this->overrideError; |
| 1010 | 1010 | $message = sprintf( |
@@ -1026,13 +1026,13 @@ discard block |
||
| 1026 | 1026 | * @return Assert |
| 1027 | 1027 | * @throws AssertionFailedException |
| 1028 | 1028 | */ |
| 1029 | - public function notNull(string $message='', string $fieldName='') : Assert |
|
| 1029 | + public function notNull(string $message = '', string $fieldName = '') : Assert |
|
| 1030 | 1030 | { |
| 1031 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1031 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1032 | 1032 | { |
| 1033 | 1033 | return $this; |
| 1034 | 1034 | } |
| 1035 | - if ( $this->value === null ) |
|
| 1035 | + if ($this->value === null) |
|
| 1036 | 1036 | { |
| 1037 | 1037 | $message = $message ?: $this->overrideError; |
| 1038 | 1038 | $message = sprintf( |
@@ -1054,13 +1054,13 @@ discard block |
||
| 1054 | 1054 | * @return Assert |
| 1055 | 1055 | * @throws AssertionFailedException |
| 1056 | 1056 | */ |
| 1057 | - public function string(string $message='', string $fieldName='') : Assert |
|
| 1057 | + public function string(string $message = '', string $fieldName = '') : Assert |
|
| 1058 | 1058 | { |
| 1059 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1059 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1060 | 1060 | { |
| 1061 | 1061 | return $this; |
| 1062 | 1062 | } |
| 1063 | - if ( !is_string($this->value) ) |
|
| 1063 | + if ( ! is_string($this->value)) |
|
| 1064 | 1064 | { |
| 1065 | 1065 | $message = $message ?: $this->overrideError; |
| 1066 | 1066 | $message = sprintf( |
@@ -1084,14 +1084,14 @@ discard block |
||
| 1084 | 1084 | * @return Assert |
| 1085 | 1085 | * @throws AssertionFailedException |
| 1086 | 1086 | */ |
| 1087 | - public function regex(string $pattern, string $message='', string $fieldName='') : Assert |
|
| 1087 | + public function regex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
| 1088 | 1088 | { |
| 1089 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1089 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1090 | 1090 | { |
| 1091 | 1091 | return $this; |
| 1092 | 1092 | } |
| 1093 | 1093 | $this->string($message, $fieldName); |
| 1094 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 1094 | + if ( ! preg_match($pattern, $this->value)) |
|
| 1095 | 1095 | { |
| 1096 | 1096 | $message = $message ?: $this->overrideError; |
| 1097 | 1097 | $message = sprintf( |
@@ -1099,7 +1099,7 @@ discard block |
||
| 1099 | 1099 | $this->stringify($this->value) |
| 1100 | 1100 | ); |
| 1101 | 1101 | |
| 1102 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
| 1102 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | return $this; |
@@ -1113,15 +1113,15 @@ discard block |
||
| 1113 | 1113 | * @return Assert |
| 1114 | 1114 | * @throws AssertionFailedException |
| 1115 | 1115 | */ |
| 1116 | - public function ipAddress(string $message='', string $fieldName='') : Assert |
|
| 1116 | + public function ipAddress(string $message = '', string $fieldName = '') : Assert |
|
| 1117 | 1117 | { |
| 1118 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1118 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1119 | 1119 | { |
| 1120 | 1120 | return $this; |
| 1121 | 1121 | } |
| 1122 | 1122 | $this->string($message, $fieldName); |
| 1123 | - $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
| 1124 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 1123 | + $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
| 1124 | + if ( ! preg_match($pattern, $this->value)) |
|
| 1125 | 1125 | { |
| 1126 | 1126 | $message = $message ?: $this->overrideError; |
| 1127 | 1127 | $message = sprintf( |
@@ -1144,14 +1144,14 @@ discard block |
||
| 1144 | 1144 | * @return Assert |
| 1145 | 1145 | * @throws AssertionFailedException |
| 1146 | 1146 | */ |
| 1147 | - public function notRegex(string $pattern, string $message='', string $fieldName='') : Assert |
|
| 1147 | + public function notRegex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
| 1148 | 1148 | { |
| 1149 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1149 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1150 | 1150 | { |
| 1151 | 1151 | return $this; |
| 1152 | 1152 | } |
| 1153 | 1153 | $this->string($message, $fieldName); |
| 1154 | - if ( preg_match($pattern, $this->value) ) |
|
| 1154 | + if (preg_match($pattern, $this->value)) |
|
| 1155 | 1155 | { |
| 1156 | 1156 | $message = $message ?: $this->overrideError; |
| 1157 | 1157 | $message = sprintf( |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | $this->stringify($this->value) |
| 1160 | 1160 | ); |
| 1161 | 1161 | |
| 1162 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
| 1162 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | return $this; |
@@ -1175,14 +1175,14 @@ discard block |
||
| 1175 | 1175 | * @return Assert |
| 1176 | 1176 | * @throws AssertionFailedException |
| 1177 | 1177 | */ |
| 1178 | - public function length(int $length, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1178 | + public function length(int $length, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1179 | 1179 | { |
| 1180 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1180 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1181 | 1181 | { |
| 1182 | 1182 | return $this; |
| 1183 | 1183 | } |
| 1184 | 1184 | $this->string($message, $fieldName); |
| 1185 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
| 1185 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
| 1186 | 1186 | { |
| 1187 | 1187 | $message = $message ?: $this->overrideError; |
| 1188 | 1188 | $message = sprintf( |
@@ -1191,7 +1191,7 @@ discard block |
||
| 1191 | 1191 | $length, |
| 1192 | 1192 | mb_strlen($this->value, $encoding) |
| 1193 | 1193 | ); |
| 1194 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
| 1194 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
| 1195 | 1195 | |
| 1196 | 1196 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $fieldName, $constraints); |
| 1197 | 1197 | } |
@@ -1210,24 +1210,24 @@ discard block |
||
| 1210 | 1210 | * @return Assert |
| 1211 | 1211 | * @throws AssertionFailedException |
| 1212 | 1212 | */ |
| 1213 | - public function minLength(int $minLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1213 | + public function minLength(int $minLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1214 | 1214 | { |
| 1215 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1215 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1216 | 1216 | { |
| 1217 | 1217 | return $this; |
| 1218 | 1218 | } |
| 1219 | 1219 | $this->string($message, $fieldName); |
| 1220 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1220 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1221 | 1221 | { |
| 1222 | 1222 | $message = $message ?: $this->overrideError; |
| 1223 | - $message = sprintf( |
|
| 1223 | + $message = sprintf( |
|
| 1224 | 1224 | $message |
| 1225 | 1225 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1226 | 1226 | $this->stringify($this->value), |
| 1227 | 1227 | $minLength, |
| 1228 | 1228 | mb_strlen($this->value, $encoding) |
| 1229 | 1229 | ); |
| 1230 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1230 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1231 | 1231 | |
| 1232 | 1232 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
| 1233 | 1233 | } |
@@ -1246,23 +1246,23 @@ discard block |
||
| 1246 | 1246 | * @return Assert |
| 1247 | 1247 | * @throws AssertionFailedException |
| 1248 | 1248 | */ |
| 1249 | - public function maxLength(int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1249 | + public function maxLength(int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1250 | 1250 | { |
| 1251 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1251 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1252 | 1252 | { |
| 1253 | 1253 | return $this; |
| 1254 | 1254 | } |
| 1255 | 1255 | $this->string($message, $fieldName); |
| 1256 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1256 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1257 | 1257 | { |
| 1258 | 1258 | $message = $message ?: $this->overrideError; |
| 1259 | - $message = sprintf( |
|
| 1259 | + $message = sprintf( |
|
| 1260 | 1260 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1261 | 1261 | $this->stringify($this->value), |
| 1262 | 1262 | $maxLength, |
| 1263 | 1263 | mb_strlen($this->value, $encoding) |
| 1264 | 1264 | ); |
| 1265 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1265 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1266 | 1266 | |
| 1267 | 1267 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
| 1268 | 1268 | } |
@@ -1281,37 +1281,37 @@ discard block |
||
| 1281 | 1281 | * @return Assert |
| 1282 | 1282 | * @throws AssertionFailedException |
| 1283 | 1283 | */ |
| 1284 | - public function betweenLength(int $minLength, int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1284 | + public function betweenLength(int $minLength, int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1285 | 1285 | { |
| 1286 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1286 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1287 | 1287 | { |
| 1288 | 1288 | return $this; |
| 1289 | 1289 | } |
| 1290 | 1290 | $this->string($message, $fieldName); |
| 1291 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1291 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1292 | 1292 | { |
| 1293 | 1293 | $message = $message ?: $this->overrideError; |
| 1294 | - $message = sprintf( |
|
| 1294 | + $message = sprintf( |
|
| 1295 | 1295 | $message |
| 1296 | 1296 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1297 | 1297 | $this->stringify($this->value), |
| 1298 | 1298 | $minLength, |
| 1299 | 1299 | mb_strlen($this->value, $encoding) |
| 1300 | 1300 | ); |
| 1301 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1301 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1302 | 1302 | |
| 1303 | 1303 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
| 1304 | 1304 | } |
| 1305 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1305 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1306 | 1306 | { |
| 1307 | 1307 | $message = $message ?: $this->overrideError; |
| 1308 | - $message = sprintf( |
|
| 1308 | + $message = sprintf( |
|
| 1309 | 1309 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1310 | 1310 | $this->stringify($this->value), |
| 1311 | 1311 | $maxLength, |
| 1312 | 1312 | mb_strlen($this->value, $encoding) |
| 1313 | 1313 | ); |
| 1314 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1314 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1315 | 1315 | |
| 1316 | 1316 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
| 1317 | 1317 | } |
@@ -1329,22 +1329,22 @@ discard block |
||
| 1329 | 1329 | * @return Assert |
| 1330 | 1330 | * @throws AssertionFailedException |
| 1331 | 1331 | */ |
| 1332 | - public function startsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1332 | + public function startsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1333 | 1333 | { |
| 1334 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1334 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1335 | 1335 | { |
| 1336 | 1336 | return $this; |
| 1337 | 1337 | } |
| 1338 | 1338 | $this->string($message, $fieldName); |
| 1339 | - if ( mb_strpos($this->value, $needle, 0, $encoding) !== 0 ) |
|
| 1339 | + if (mb_strpos($this->value, $needle, 0, $encoding) !== 0) |
|
| 1340 | 1340 | { |
| 1341 | 1341 | $message = $message ?: $this->overrideError; |
| 1342 | - $message = sprintf( |
|
| 1342 | + $message = sprintf( |
|
| 1343 | 1343 | $message ?: 'Value "%s" does not start with "%s".', |
| 1344 | 1344 | $this->stringify($this->value), |
| 1345 | 1345 | $this->stringify($needle) |
| 1346 | 1346 | ); |
| 1347 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1347 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1348 | 1348 | |
| 1349 | 1349 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $fieldName, $constraints); |
| 1350 | 1350 | } |
@@ -1362,23 +1362,23 @@ discard block |
||
| 1362 | 1362 | * @return Assert |
| 1363 | 1363 | * @throws AssertionFailedException |
| 1364 | 1364 | */ |
| 1365 | - public function endsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1365 | + public function endsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1366 | 1366 | { |
| 1367 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1367 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1368 | 1368 | { |
| 1369 | 1369 | return $this; |
| 1370 | 1370 | } |
| 1371 | 1371 | $this->string($message, $fieldName); |
| 1372 | 1372 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
| 1373 | - if ( mb_strripos($this->value, $needle, 0 , $encoding) !== $stringPosition ) |
|
| 1373 | + if (mb_strripos($this->value, $needle, 0, $encoding) !== $stringPosition) |
|
| 1374 | 1374 | { |
| 1375 | 1375 | $message = $message ?: $this->overrideError; |
| 1376 | - $message = sprintf( |
|
| 1376 | + $message = sprintf( |
|
| 1377 | 1377 | $message ?: 'Value "%s" does not end with "%s".', |
| 1378 | 1378 | $this->stringify($this->value), |
| 1379 | 1379 | $this->stringify($needle) |
| 1380 | 1380 | ); |
| 1381 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1381 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1382 | 1382 | |
| 1383 | 1383 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $fieldName, $constraints); |
| 1384 | 1384 | } |
@@ -1396,22 +1396,22 @@ discard block |
||
| 1396 | 1396 | * @return Assert |
| 1397 | 1397 | * @throws AssertionFailedException |
| 1398 | 1398 | */ |
| 1399 | - public function contains(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1399 | + public function contains(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1400 | 1400 | { |
| 1401 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1401 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1402 | 1402 | { |
| 1403 | 1403 | return $this; |
| 1404 | 1404 | } |
| 1405 | 1405 | $this->string($message, $fieldName); |
| 1406 | - if ( mb_strpos($this->value, $needle, 0, $encoding) === false ) |
|
| 1406 | + if (mb_strpos($this->value, $needle, 0, $encoding) === false) |
|
| 1407 | 1407 | { |
| 1408 | 1408 | $message = $message ?: $this->overrideError; |
| 1409 | - $message = sprintf( |
|
| 1409 | + $message = sprintf( |
|
| 1410 | 1410 | $message ?: 'Value "%s" does not contain "%s".', |
| 1411 | 1411 | $this->stringify($this->value), |
| 1412 | 1412 | $this->stringify($needle) |
| 1413 | 1413 | ); |
| 1414 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1414 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1415 | 1415 | |
| 1416 | 1416 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $fieldName, $constraints); |
| 1417 | 1417 | } |
@@ -1428,13 +1428,13 @@ discard block |
||
| 1428 | 1428 | * @return Assert |
| 1429 | 1429 | * @throws AssertionFailedException |
| 1430 | 1430 | */ |
| 1431 | - public function choice(array $choices, string $message='', string $fieldName='') : Assert |
|
| 1431 | + public function choice(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 1432 | 1432 | { |
| 1433 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1433 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1434 | 1434 | { |
| 1435 | 1435 | return $this; |
| 1436 | 1436 | } |
| 1437 | - if ( !in_array($this->value, $choices, true) ) |
|
| 1437 | + if ( ! in_array($this->value, $choices, true)) |
|
| 1438 | 1438 | { |
| 1439 | 1439 | $message = $message ?: $this->overrideError; |
| 1440 | 1440 | $message = sprintf( |
@@ -1443,7 +1443,7 @@ discard block |
||
| 1443 | 1443 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
| 1444 | 1444 | ); |
| 1445 | 1445 | |
| 1446 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, ['choices' => $choices]); |
|
| 1446 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, [ 'choices' => $choices ]); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | return $this; |
@@ -1458,9 +1458,9 @@ discard block |
||
| 1458 | 1458 | * @return Assert |
| 1459 | 1459 | * @throws AssertionFailedException |
| 1460 | 1460 | */ |
| 1461 | - public function inArray(array $choices, string $message='', string $fieldName='') : Assert |
|
| 1461 | + public function inArray(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 1462 | 1462 | { |
| 1463 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1463 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1464 | 1464 | { |
| 1465 | 1465 | return $this; |
| 1466 | 1466 | } |
@@ -1477,13 +1477,13 @@ discard block |
||
| 1477 | 1477 | * @return Assert |
| 1478 | 1478 | * @throws AssertionFailedException |
| 1479 | 1479 | */ |
| 1480 | - public function numeric(string $message='', string $fieldName='') : Assert |
|
| 1480 | + public function numeric(string $message = '', string $fieldName = '') : Assert |
|
| 1481 | 1481 | { |
| 1482 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1482 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1483 | 1483 | { |
| 1484 | 1484 | return $this; |
| 1485 | 1485 | } |
| 1486 | - if ( ! is_numeric($this->value) ) |
|
| 1486 | + if ( ! is_numeric($this->value)) |
|
| 1487 | 1487 | { |
| 1488 | 1488 | $message = $message ?: $this->overrideError; |
| 1489 | 1489 | $message = sprintf( |
@@ -1505,7 +1505,7 @@ discard block |
||
| 1505 | 1505 | * @return Assert |
| 1506 | 1506 | * @throws AssertionFailedException |
| 1507 | 1507 | */ |
| 1508 | - public function nonEmptyArray(string $message='', string $fieldName='') : Assert |
|
| 1508 | + public function nonEmptyArray(string $message = '', string $fieldName = '') : Assert |
|
| 1509 | 1509 | { |
| 1510 | 1510 | $message = $message ?: 'Value "%s" is not a non-empty array.'; |
| 1511 | 1511 | |
@@ -1520,7 +1520,7 @@ discard block |
||
| 1520 | 1520 | * @return Assert |
| 1521 | 1521 | * @throws AssertionFailedException |
| 1522 | 1522 | */ |
| 1523 | - public function nonEmptyInt(string $message='', string $fieldName='') : Assert |
|
| 1523 | + public function nonEmptyInt(string $message = '', string $fieldName = '') : Assert |
|
| 1524 | 1524 | { |
| 1525 | 1525 | $message = $message ?: 'Value "%s" is not a non-empty integer.'; |
| 1526 | 1526 | |
@@ -1535,7 +1535,7 @@ discard block |
||
| 1535 | 1535 | * @return Assert |
| 1536 | 1536 | * @throws AssertionFailedException |
| 1537 | 1537 | */ |
| 1538 | - public function nonEmptyString(string $message='', string $fieldName='') : Assert |
|
| 1538 | + public function nonEmptyString(string $message = '', string $fieldName = '') : Assert |
|
| 1539 | 1539 | { |
| 1540 | 1540 | $message = $message ?: 'Value "%s" is not a non-empty string.'; |
| 1541 | 1541 | |
@@ -1550,13 +1550,13 @@ discard block |
||
| 1550 | 1550 | * @return Assert |
| 1551 | 1551 | * @throws AssertionFailedException |
| 1552 | 1552 | */ |
| 1553 | - public function isArray(string $message='', string $fieldName='') : Assert |
|
| 1553 | + public function isArray(string $message = '', string $fieldName = '') : Assert |
|
| 1554 | 1554 | { |
| 1555 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1555 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1556 | 1556 | { |
| 1557 | 1557 | return $this; |
| 1558 | 1558 | } |
| 1559 | - if ( !is_array($this->value) ) |
|
| 1559 | + if ( ! is_array($this->value)) |
|
| 1560 | 1560 | { |
| 1561 | 1561 | $message = $message ?: $this->overrideError; |
| 1562 | 1562 | $message = sprintf( |
@@ -1578,13 +1578,13 @@ discard block |
||
| 1578 | 1578 | * @return Assert |
| 1579 | 1579 | * @throws AssertionFailedException |
| 1580 | 1580 | */ |
| 1581 | - public function isTraversable(string $message='', string $fieldName='') : Assert |
|
| 1581 | + public function isTraversable(string $message = '', string $fieldName = '') : Assert |
|
| 1582 | 1582 | { |
| 1583 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1583 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1584 | 1584 | { |
| 1585 | 1585 | return $this; |
| 1586 | 1586 | } |
| 1587 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
| 1587 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
| 1588 | 1588 | { |
| 1589 | 1589 | $message = $message ?: $this->overrideError; |
| 1590 | 1590 | $message = sprintf( |
@@ -1606,13 +1606,13 @@ discard block |
||
| 1606 | 1606 | * @return Assert |
| 1607 | 1607 | * @throws AssertionFailedException |
| 1608 | 1608 | */ |
| 1609 | - public function isArrayAccessible(string $message='', string $fieldName='') : Assert |
|
| 1609 | + public function isArrayAccessible(string $message = '', string $fieldName = '') : Assert |
|
| 1610 | 1610 | { |
| 1611 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1611 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1612 | 1612 | { |
| 1613 | 1613 | return $this; |
| 1614 | 1614 | } |
| 1615 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
| 1615 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
| 1616 | 1616 | { |
| 1617 | 1617 | $message = $message ?: $this->overrideError; |
| 1618 | 1618 | $message = sprintf( |
@@ -1635,14 +1635,14 @@ discard block |
||
| 1635 | 1635 | * @return Assert |
| 1636 | 1636 | * @throws AssertionFailedException |
| 1637 | 1637 | */ |
| 1638 | - public function keyExists($key, string $message='', string $fieldName='') : Assert |
|
| 1638 | + public function keyExists($key, string $message = '', string $fieldName = '') : Assert |
|
| 1639 | 1639 | { |
| 1640 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1640 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1641 | 1641 | { |
| 1642 | 1642 | return $this; |
| 1643 | 1643 | } |
| 1644 | 1644 | $this->isArray($message, $fieldName); |
| 1645 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1645 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1646 | 1646 | { |
| 1647 | 1647 | $message = $message ?: $this->overrideError; |
| 1648 | 1648 | $message = sprintf( |
@@ -1650,7 +1650,7 @@ discard block |
||
| 1650 | 1650 | $this->stringify($key) |
| 1651 | 1651 | ); |
| 1652 | 1652 | |
| 1653 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, ['key' => $key]); |
|
| 1653 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | return $this; |
@@ -1665,23 +1665,23 @@ discard block |
||
| 1665 | 1665 | * @return Assert |
| 1666 | 1666 | * @throws AssertionFailedException |
| 1667 | 1667 | */ |
| 1668 | - public function keysExist(array $keys, string $message='', string $fieldName='') : Assert |
|
| 1668 | + public function keysExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
| 1669 | 1669 | { |
| 1670 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1670 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1671 | 1671 | { |
| 1672 | 1672 | return $this; |
| 1673 | 1673 | } |
| 1674 | 1674 | $this->isArray($message, $fieldName); |
| 1675 | - foreach ( $keys as $key ) |
|
| 1675 | + foreach ($keys as $key) |
|
| 1676 | 1676 | { |
| 1677 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1677 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1678 | 1678 | { |
| 1679 | 1679 | $message = $message |
| 1680 | 1680 | ?: sprintf( |
| 1681 | 1681 | 'Array does not contain an element with key "%s"', |
| 1682 | 1682 | $this->stringify($key) |
| 1683 | 1683 | ); |
| 1684 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, ['key' => $key]); |
|
| 1684 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, [ 'key' => $key ]); |
|
| 1685 | 1685 | } |
| 1686 | 1686 | } |
| 1687 | 1687 | |
@@ -1697,14 +1697,14 @@ discard block |
||
| 1697 | 1697 | * @return Assert |
| 1698 | 1698 | * @throws AssertionFailedException |
| 1699 | 1699 | */ |
| 1700 | - public function propertyExists($key, string $message='', string $fieldName='') : Assert |
|
| 1700 | + public function propertyExists($key, string $message = '', string $fieldName = '') : Assert |
|
| 1701 | 1701 | { |
| 1702 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1702 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1703 | 1703 | { |
| 1704 | 1704 | return $this; |
| 1705 | 1705 | } |
| 1706 | 1706 | $this->isObject($message, $fieldName); |
| 1707 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1707 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1708 | 1708 | { |
| 1709 | 1709 | $message = $message |
| 1710 | 1710 | ?: sprintf( |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | $this->stringify($key) |
| 1713 | 1713 | ); |
| 1714 | 1714 | |
| 1715 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, ['key' => $key]); |
|
| 1715 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | return $this; |
@@ -1727,24 +1727,24 @@ discard block |
||
| 1727 | 1727 | * @return Assert |
| 1728 | 1728 | * @throws AssertionFailedException |
| 1729 | 1729 | */ |
| 1730 | - public function propertiesExist(array $keys, string $message='', string $fieldName='') : Assert |
|
| 1730 | + public function propertiesExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
| 1731 | 1731 | { |
| 1732 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1732 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1733 | 1733 | { |
| 1734 | 1734 | return $this; |
| 1735 | 1735 | } |
| 1736 | 1736 | $this->isObject($message, $fieldName); |
| 1737 | - foreach ( $keys as $key ) |
|
| 1737 | + foreach ($keys as $key) |
|
| 1738 | 1738 | { |
| 1739 | 1739 | // Using isset to allow resolution of magically defined properties |
| 1740 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1740 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1741 | 1741 | { |
| 1742 | 1742 | $message = $message |
| 1743 | 1743 | ?: sprintf( |
| 1744 | 1744 | 'Object does not contain a property with key "%s"', |
| 1745 | 1745 | $this->stringify($key) |
| 1746 | 1746 | ); |
| 1747 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, ['key' => $key]); |
|
| 1747 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, [ 'key' => $key ]); |
|
| 1748 | 1748 | } |
| 1749 | 1749 | } |
| 1750 | 1750 | |
@@ -1759,14 +1759,14 @@ discard block |
||
| 1759 | 1759 | * @return Assert |
| 1760 | 1760 | * @throws AssertionFailedException |
| 1761 | 1761 | */ |
| 1762 | - public function utf8(string $message='', string $fieldName='') : Assert |
|
| 1762 | + public function utf8(string $message = '', string $fieldName = '') : Assert |
|
| 1763 | 1763 | { |
| 1764 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1764 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1765 | 1765 | { |
| 1766 | 1766 | return $this; |
| 1767 | 1767 | } |
| 1768 | 1768 | $this->string($message, $fieldName); |
| 1769 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1769 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
| 1770 | 1770 | { |
| 1771 | 1771 | $message = $message |
| 1772 | 1772 | ?: sprintf( |
@@ -1789,14 +1789,14 @@ discard block |
||
| 1789 | 1789 | * @return Assert |
| 1790 | 1790 | * @throws AssertionFailedException |
| 1791 | 1791 | */ |
| 1792 | - public function ascii(string $message='', string $fieldName='') : Assert |
|
| 1792 | + public function ascii(string $message = '', string $fieldName = '') : Assert |
|
| 1793 | 1793 | { |
| 1794 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1794 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1795 | 1795 | { |
| 1796 | 1796 | return $this; |
| 1797 | 1797 | } |
| 1798 | 1798 | $this->string($message, $fieldName); |
| 1799 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1799 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
| 1800 | 1800 | { |
| 1801 | 1801 | $message = $message |
| 1802 | 1802 | ?: sprintf( |
@@ -1820,14 +1820,14 @@ discard block |
||
| 1820 | 1820 | * @return Assert |
| 1821 | 1821 | * @throws AssertionFailedException |
| 1822 | 1822 | */ |
| 1823 | - public function keyIsset($key, string $message='', string $fieldName='') : Assert |
|
| 1823 | + public function keyIsset($key, string $message = '', string $fieldName = '') : Assert |
|
| 1824 | 1824 | { |
| 1825 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1825 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1826 | 1826 | { |
| 1827 | 1827 | return $this; |
| 1828 | 1828 | } |
| 1829 | 1829 | $this->isArrayAccessible($message, $fieldName); |
| 1830 | - if ( !isset( $this->value[$key] ) ) |
|
| 1830 | + if ( ! isset($this->value[ $key ])) |
|
| 1831 | 1831 | { |
| 1832 | 1832 | $message = $message ?: $this->overrideError; |
| 1833 | 1833 | $message = sprintf( |
@@ -1835,7 +1835,7 @@ discard block |
||
| 1835 | 1835 | $this->stringify($key) |
| 1836 | 1836 | ); |
| 1837 | 1837 | |
| 1838 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, ['key' => $key]); |
|
| 1838 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, [ 'key' => $key ]); |
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | return $this; |
@@ -1851,14 +1851,14 @@ discard block |
||
| 1851 | 1851 | * @return Assert |
| 1852 | 1852 | * @throws AssertionFailedException |
| 1853 | 1853 | */ |
| 1854 | - public function notEmptyKey($key, string $message='', string $fieldName='') : Assert |
|
| 1854 | + public function notEmptyKey($key, string $message = '', string $fieldName = '') : Assert |
|
| 1855 | 1855 | { |
| 1856 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1856 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1857 | 1857 | { |
| 1858 | 1858 | return $this; |
| 1859 | 1859 | } |
| 1860 | 1860 | $this->keyIsset($key, $message, $fieldName); |
| 1861 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
| 1861 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
| 1862 | 1862 | |
| 1863 | 1863 | return $this; |
| 1864 | 1864 | } |
@@ -1871,13 +1871,13 @@ discard block |
||
| 1871 | 1871 | * @return Assert |
| 1872 | 1872 | * @throws AssertionFailedException |
| 1873 | 1873 | */ |
| 1874 | - public function notBlank(string $message='', string $fieldName='') : Assert |
|
| 1874 | + public function notBlank(string $message = '', string $fieldName = '') : Assert |
|
| 1875 | 1875 | { |
| 1876 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1876 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1877 | 1877 | { |
| 1878 | 1878 | return $this; |
| 1879 | 1879 | } |
| 1880 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
| 1880 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
| 1881 | 1881 | { |
| 1882 | 1882 | $message = $message ?: $this->overrideError; |
| 1883 | 1883 | $message = sprintf( |
@@ -1900,13 +1900,13 @@ discard block |
||
| 1900 | 1900 | * @return Assert |
| 1901 | 1901 | * @throws AssertionFailedException |
| 1902 | 1902 | */ |
| 1903 | - public function isInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1903 | + public function isInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1904 | 1904 | { |
| 1905 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1905 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1906 | 1906 | { |
| 1907 | 1907 | return $this; |
| 1908 | 1908 | } |
| 1909 | - if ( !( $this->value instanceof $className ) ) |
|
| 1909 | + if ( ! ($this->value instanceof $className)) |
|
| 1910 | 1910 | { |
| 1911 | 1911 | $message = $message ?: $this->overrideError; |
| 1912 | 1912 | $message = sprintf( |
@@ -1915,7 +1915,7 @@ discard block |
||
| 1915 | 1915 | $className |
| 1916 | 1916 | ); |
| 1917 | 1917 | |
| 1918 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
| 1918 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | return $this; |
@@ -1930,13 +1930,13 @@ discard block |
||
| 1930 | 1930 | * @return Assert |
| 1931 | 1931 | * @throws AssertionFailedException |
| 1932 | 1932 | */ |
| 1933 | - public function notIsInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1933 | + public function notIsInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1934 | 1934 | { |
| 1935 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1935 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1936 | 1936 | { |
| 1937 | 1937 | return $this; |
| 1938 | 1938 | } |
| 1939 | - if ( $this->value instanceof $className ) |
|
| 1939 | + if ($this->value instanceof $className) |
|
| 1940 | 1940 | { |
| 1941 | 1941 | $message = $message ?: $this->overrideError; |
| 1942 | 1942 | $message = sprintf( |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | $className |
| 1946 | 1946 | ); |
| 1947 | 1947 | |
| 1948 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
| 1948 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | return $this; |
@@ -1960,13 +1960,13 @@ discard block |
||
| 1960 | 1960 | * @return Assert |
| 1961 | 1961 | * @throws AssertionFailedException |
| 1962 | 1962 | */ |
| 1963 | - public function subclassOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1963 | + public function subclassOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1964 | 1964 | { |
| 1965 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1965 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1966 | 1966 | { |
| 1967 | 1967 | return $this; |
| 1968 | 1968 | } |
| 1969 | - if ( !is_subclass_of($this->value, $className) ) |
|
| 1969 | + if ( ! is_subclass_of($this->value, $className)) |
|
| 1970 | 1970 | { |
| 1971 | 1971 | $message = $message ?: $this->overrideError; |
| 1972 | 1972 | $message = sprintf( |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | $className |
| 1976 | 1976 | ); |
| 1977 | 1977 | |
| 1978 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, ['class' => $className]); |
|
| 1978 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, [ 'class' => $className ]); |
|
| 1979 | 1979 | } |
| 1980 | 1980 | |
| 1981 | 1981 | return $this; |
@@ -1991,14 +1991,14 @@ discard block |
||
| 1991 | 1991 | * @return Assert |
| 1992 | 1992 | * @throws AssertionFailedException |
| 1993 | 1993 | */ |
| 1994 | - public function range(float $minValue, float $maxValue, string $message='', string $fieldName='') : Assert |
|
| 1994 | + public function range(float $minValue, float $maxValue, string $message = '', string $fieldName = '') : Assert |
|
| 1995 | 1995 | { |
| 1996 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1996 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1997 | 1997 | { |
| 1998 | 1998 | return $this; |
| 1999 | 1999 | } |
| 2000 | 2000 | $this->numeric($message, $fieldName); |
| 2001 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
| 2001 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
| 2002 | 2002 | { |
| 2003 | 2003 | $message = $message ?: $this->overrideError; |
| 2004 | 2004 | $message = sprintf( |
@@ -2026,14 +2026,14 @@ discard block |
||
| 2026 | 2026 | * @return Assert |
| 2027 | 2027 | * @throws AssertionFailedException |
| 2028 | 2028 | */ |
| 2029 | - public function min(int $minValue, string $message='', string $fieldName='') : Assert |
|
| 2029 | + public function min(int $minValue, string $message = '', string $fieldName = '') : Assert |
|
| 2030 | 2030 | { |
| 2031 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2031 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2032 | 2032 | { |
| 2033 | 2033 | return $this; |
| 2034 | 2034 | } |
| 2035 | 2035 | $this->numeric($message, $fieldName); |
| 2036 | - if ( $this->value < $minValue ) |
|
| 2036 | + if ($this->value < $minValue) |
|
| 2037 | 2037 | { |
| 2038 | 2038 | $message = $message ?: $this->overrideError; |
| 2039 | 2039 | $message = sprintf( |
@@ -2042,7 +2042,7 @@ discard block |
||
| 2042 | 2042 | $this->stringify($minValue) |
| 2043 | 2043 | ); |
| 2044 | 2044 | |
| 2045 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, ['min' => $minValue]); |
|
| 2045 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, [ 'min' => $minValue ]); |
|
| 2046 | 2046 | } |
| 2047 | 2047 | |
| 2048 | 2048 | return $this; |
@@ -2057,14 +2057,14 @@ discard block |
||
| 2057 | 2057 | * @return Assert |
| 2058 | 2058 | * @throws AssertionFailedException |
| 2059 | 2059 | */ |
| 2060 | - public function max(int $maxValue, string $message='', string $fieldName='') : Assert |
|
| 2060 | + public function max(int $maxValue, string $message = '', string $fieldName = '') : Assert |
|
| 2061 | 2061 | { |
| 2062 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2062 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2063 | 2063 | { |
| 2064 | 2064 | return $this; |
| 2065 | 2065 | } |
| 2066 | 2066 | $this->numeric($message, $fieldName); |
| 2067 | - if ( $this->value > $maxValue ) |
|
| 2067 | + if ($this->value > $maxValue) |
|
| 2068 | 2068 | { |
| 2069 | 2069 | $message = $message ?: $this->overrideError; |
| 2070 | 2070 | $message = sprintf( |
@@ -2073,7 +2073,7 @@ discard block |
||
| 2073 | 2073 | $this->stringify($maxValue) |
| 2074 | 2074 | ); |
| 2075 | 2075 | |
| 2076 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, ['max' => $maxValue]); |
|
| 2076 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, [ 'max' => $maxValue ]); |
|
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | 2079 | return $this; |
@@ -2087,15 +2087,15 @@ discard block |
||
| 2087 | 2087 | * @return Assert |
| 2088 | 2088 | * @throws AssertionFailedException |
| 2089 | 2089 | */ |
| 2090 | - public function file(string $message='', string $fieldName='') : Assert |
|
| 2090 | + public function file(string $message = '', string $fieldName = '') : Assert |
|
| 2091 | 2091 | { |
| 2092 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2092 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2093 | 2093 | { |
| 2094 | 2094 | return $this; |
| 2095 | 2095 | } |
| 2096 | 2096 | $this->string($message, $fieldName); |
| 2097 | 2097 | $this->notEmpty($message, $fieldName); |
| 2098 | - if ( !is_file($this->value) ) |
|
| 2098 | + if ( ! is_file($this->value)) |
|
| 2099 | 2099 | { |
| 2100 | 2100 | $message = $message ?: $this->overrideError; |
| 2101 | 2101 | $message = sprintf( |
@@ -2117,15 +2117,15 @@ discard block |
||
| 2117 | 2117 | * @return Assert |
| 2118 | 2118 | * @throws AssertionFailedException |
| 2119 | 2119 | */ |
| 2120 | - public function fileOrDirectoryExists(string $message='', string $fieldName='') : Assert |
|
| 2120 | + public function fileOrDirectoryExists(string $message = '', string $fieldName = '') : Assert |
|
| 2121 | 2121 | { |
| 2122 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2122 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2123 | 2123 | { |
| 2124 | 2124 | return $this; |
| 2125 | 2125 | } |
| 2126 | 2126 | $this->string($message, $fieldName); |
| 2127 | 2127 | $this->notEmpty($message, $fieldName); |
| 2128 | - if ( ! file_exists($this->value) ) |
|
| 2128 | + if ( ! file_exists($this->value)) |
|
| 2129 | 2129 | { |
| 2130 | 2130 | $message = $message ?: $this->overrideError; |
| 2131 | 2131 | $message = sprintf( |
@@ -2147,14 +2147,14 @@ discard block |
||
| 2147 | 2147 | * @return Assert |
| 2148 | 2148 | * @throws AssertionFailedException |
| 2149 | 2149 | */ |
| 2150 | - public function directory(string $message='', string $fieldName='') : Assert |
|
| 2150 | + public function directory(string $message = '', string $fieldName = '') : Assert |
|
| 2151 | 2151 | { |
| 2152 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2152 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2153 | 2153 | { |
| 2154 | 2154 | return $this; |
| 2155 | 2155 | } |
| 2156 | 2156 | $this->string($message, $fieldName); |
| 2157 | - if ( !is_dir($this->value) ) |
|
| 2157 | + if ( ! is_dir($this->value)) |
|
| 2158 | 2158 | { |
| 2159 | 2159 | $message = $message ?: $this->overrideError; |
| 2160 | 2160 | $message = sprintf( |
@@ -2176,14 +2176,14 @@ discard block |
||
| 2176 | 2176 | * @return Assert |
| 2177 | 2177 | * @throws AssertionFailedException |
| 2178 | 2178 | */ |
| 2179 | - public function readable(string $message='', string $fieldName='') : Assert |
|
| 2179 | + public function readable(string $message = '', string $fieldName = '') : Assert |
|
| 2180 | 2180 | { |
| 2181 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2181 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2182 | 2182 | { |
| 2183 | 2183 | return $this; |
| 2184 | 2184 | } |
| 2185 | 2185 | $this->string($message, $fieldName); |
| 2186 | - if ( !is_readable($this->value) ) |
|
| 2186 | + if ( ! is_readable($this->value)) |
|
| 2187 | 2187 | { |
| 2188 | 2188 | $message = $message ?: $this->overrideError; |
| 2189 | 2189 | $message = sprintf( |
@@ -2205,14 +2205,14 @@ discard block |
||
| 2205 | 2205 | * @return Assert |
| 2206 | 2206 | * @throws AssertionFailedException |
| 2207 | 2207 | */ |
| 2208 | - public function writeable(string $message='', string $fieldName='') : Assert |
|
| 2208 | + public function writeable(string $message = '', string $fieldName = '') : Assert |
|
| 2209 | 2209 | { |
| 2210 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2210 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2211 | 2211 | { |
| 2212 | 2212 | return $this; |
| 2213 | 2213 | } |
| 2214 | 2214 | $this->string($message, $fieldName); |
| 2215 | - if ( !is_writeable($this->value) ) |
|
| 2215 | + if ( ! is_writeable($this->value)) |
|
| 2216 | 2216 | { |
| 2217 | 2217 | $message = $message ?: $this->overrideError; |
| 2218 | 2218 | $message = sprintf( |
@@ -2234,14 +2234,14 @@ discard block |
||
| 2234 | 2234 | * @return Assert |
| 2235 | 2235 | * @throws AssertionFailedException |
| 2236 | 2236 | */ |
| 2237 | - public function email(string $message='', string $fieldName='') : Assert |
|
| 2237 | + public function email(string $message = '', string $fieldName = '') : Assert |
|
| 2238 | 2238 | { |
| 2239 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2239 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2240 | 2240 | { |
| 2241 | 2241 | return $this; |
| 2242 | 2242 | } |
| 2243 | 2243 | $this->string($message, $fieldName); |
| 2244 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
| 2244 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
| 2245 | 2245 | { |
| 2246 | 2246 | $message = $message ?: $this->overrideError; |
| 2247 | 2247 | $message = sprintf( |
@@ -2255,7 +2255,7 @@ discard block |
||
| 2255 | 2255 | { |
| 2256 | 2256 | $host = substr($this->value, strpos($this->value, '@') + 1); |
| 2257 | 2257 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
| 2258 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
| 2258 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
| 2259 | 2259 | { |
| 2260 | 2260 | $message = $message ?: $this->overrideError; |
| 2261 | 2261 | $message = sprintf( |
@@ -2277,9 +2277,9 @@ discard block |
||
| 2277 | 2277 | * @return Assert |
| 2278 | 2278 | * @throws AssertionFailedException |
| 2279 | 2279 | */ |
| 2280 | - public function emailPrefix(string $message='', string $fieldName='') : Assert |
|
| 2280 | + public function emailPrefix(string $message = '', string $fieldName = '') : Assert |
|
| 2281 | 2281 | { |
| 2282 | - $this->value($this->value . '@example.com'); |
|
| 2282 | + $this->value($this->value.'@example.com'); |
|
| 2283 | 2283 | |
| 2284 | 2284 | return $this->email($message, $fieldName); |
| 2285 | 2285 | } |
@@ -2298,14 +2298,14 @@ discard block |
||
| 2298 | 2298 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
| 2299 | 2299 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
| 2300 | 2300 | */ |
| 2301 | - public function url(string $message='', string $fieldName='') : Assert |
|
| 2301 | + public function url(string $message = '', string $fieldName = '') : Assert |
|
| 2302 | 2302 | { |
| 2303 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2303 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2304 | 2304 | { |
| 2305 | 2305 | return $this; |
| 2306 | 2306 | } |
| 2307 | 2307 | $this->string($message, $fieldName); |
| 2308 | - $protocols = ['http', 'https']; |
|
| 2308 | + $protocols = [ 'http', 'https' ]; |
|
| 2309 | 2309 | $pattern = '~^ |
| 2310 | 2310 | (%s):// # protocol |
| 2311 | 2311 | ( |
@@ -2320,8 +2320,8 @@ discard block |
||
| 2320 | 2320 | (:[0-9]+)? # a port (optional) |
| 2321 | 2321 | (/?|/\S+) # a /, nothing or a / with something |
| 2322 | 2322 | $~ixu'; |
| 2323 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2324 | - if ( !preg_match($pattern, $this->value) ) |
|
| 2323 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2324 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2325 | 2325 | { |
| 2326 | 2326 | $message = $message ?: $this->overrideError; |
| 2327 | 2327 | $message = sprintf( |
@@ -2346,15 +2346,15 @@ discard block |
||
| 2346 | 2346 | * @throws AssertionFailedException |
| 2347 | 2347 | * |
| 2348 | 2348 | */ |
| 2349 | - public function domainName(string $message='', string $fieldName='') : Assert |
|
| 2349 | + public function domainName(string $message = '', string $fieldName = '') : Assert |
|
| 2350 | 2350 | { |
| 2351 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2351 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2352 | 2352 | { |
| 2353 | 2353 | return $this; |
| 2354 | 2354 | } |
| 2355 | 2355 | $this->string($message, $fieldName); |
| 2356 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2357 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 2356 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2357 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2358 | 2358 | { |
| 2359 | 2359 | $message = $message ?: $this->overrideError; |
| 2360 | 2360 | $message = sprintf( |
@@ -2376,9 +2376,9 @@ discard block |
||
| 2376 | 2376 | * @return Assert |
| 2377 | 2377 | * @throws AssertionFailedException |
| 2378 | 2378 | */ |
| 2379 | - public function ausMobile(string $message='', string $fieldName='') : Assert |
|
| 2379 | + public function ausMobile(string $message = '', string $fieldName = '') : Assert |
|
| 2380 | 2380 | { |
| 2381 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2381 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2382 | 2382 | { |
| 2383 | 2383 | return $this; |
| 2384 | 2384 | } |
@@ -2386,7 +2386,7 @@ discard block |
||
| 2386 | 2386 | { |
| 2387 | 2387 | $this->regex('/^04([0-9]{8})$/', $message, $fieldName); |
| 2388 | 2388 | } |
| 2389 | - catch ( AssertionFailedException $e ) |
|
| 2389 | + catch (AssertionFailedException $e) |
|
| 2390 | 2390 | { |
| 2391 | 2391 | $message = $message ?: $this->overrideError; |
| 2392 | 2392 | $message = sprintf( |
@@ -2409,9 +2409,9 @@ discard block |
||
| 2409 | 2409 | * @return Assert |
| 2410 | 2410 | * @throws AssertionFailedException |
| 2411 | 2411 | */ |
| 2412 | - public function alnum(string $message='', string $fieldName='') : Assert |
|
| 2412 | + public function alnum(string $message = '', string $fieldName = '') : Assert |
|
| 2413 | 2413 | { |
| 2414 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2414 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2415 | 2415 | { |
| 2416 | 2416 | return $this; |
| 2417 | 2417 | } |
@@ -2442,13 +2442,13 @@ discard block |
||
| 2442 | 2442 | * @return Assert |
| 2443 | 2443 | * @throws AssertionFailedException |
| 2444 | 2444 | */ |
| 2445 | - public function true(string $message='', string $fieldName='') : Assert |
|
| 2445 | + public function true(string $message = '', string $fieldName = '') : Assert |
|
| 2446 | 2446 | { |
| 2447 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2447 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2448 | 2448 | { |
| 2449 | 2449 | return $this; |
| 2450 | 2450 | } |
| 2451 | - if ( $this->value !== true ) |
|
| 2451 | + if ($this->value !== true) |
|
| 2452 | 2452 | { |
| 2453 | 2453 | $message = $message ?: $this->overrideError; |
| 2454 | 2454 | $message = sprintf( |
@@ -2470,13 +2470,13 @@ discard block |
||
| 2470 | 2470 | * @return Assert |
| 2471 | 2471 | * @throws AssertionFailedException |
| 2472 | 2472 | */ |
| 2473 | - public function truthy(string $message='', string $fieldName='') : Assert |
|
| 2473 | + public function truthy(string $message = '', string $fieldName = '') : Assert |
|
| 2474 | 2474 | { |
| 2475 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2475 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2476 | 2476 | { |
| 2477 | 2477 | return $this; |
| 2478 | 2478 | } |
| 2479 | - if ( ! $this->value ) |
|
| 2479 | + if ( ! $this->value) |
|
| 2480 | 2480 | { |
| 2481 | 2481 | $message = $message ?: $this->overrideError; |
| 2482 | 2482 | $message = sprintf( |
@@ -2498,13 +2498,13 @@ discard block |
||
| 2498 | 2498 | * @return Assert |
| 2499 | 2499 | * @throws AssertionFailedException |
| 2500 | 2500 | */ |
| 2501 | - public function false(string $message='', string $fieldName='') : Assert |
|
| 2501 | + public function false(string $message = '', string $fieldName = '') : Assert |
|
| 2502 | 2502 | { |
| 2503 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2503 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2504 | 2504 | { |
| 2505 | 2505 | return $this; |
| 2506 | 2506 | } |
| 2507 | - if ( $this->value !== false ) |
|
| 2507 | + if ($this->value !== false) |
|
| 2508 | 2508 | { |
| 2509 | 2509 | $message = $message ?: $this->overrideError; |
| 2510 | 2510 | $message = sprintf( |
@@ -2526,13 +2526,13 @@ discard block |
||
| 2526 | 2526 | * @return Assert |
| 2527 | 2527 | * @throws AssertionFailedException |
| 2528 | 2528 | */ |
| 2529 | - public function notFalse(string $message='', string $fieldName='') : Assert |
|
| 2529 | + public function notFalse(string $message = '', string $fieldName = '') : Assert |
|
| 2530 | 2530 | { |
| 2531 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2531 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2532 | 2532 | { |
| 2533 | 2533 | return $this; |
| 2534 | 2534 | } |
| 2535 | - if ( $this->value === false ) |
|
| 2535 | + if ($this->value === false) |
|
| 2536 | 2536 | { |
| 2537 | 2537 | $message = $message ?: $this->overrideError; |
| 2538 | 2538 | $message = sprintf( |
@@ -2554,13 +2554,13 @@ discard block |
||
| 2554 | 2554 | * @return Assert |
| 2555 | 2555 | * @throws AssertionFailedException |
| 2556 | 2556 | */ |
| 2557 | - public function classExists(string $message='', string $fieldName='') : Assert |
|
| 2557 | + public function classExists(string $message = '', string $fieldName = '') : Assert |
|
| 2558 | 2558 | { |
| 2559 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2559 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2560 | 2560 | { |
| 2561 | 2561 | return $this; |
| 2562 | 2562 | } |
| 2563 | - if ( !class_exists($this->value) ) |
|
| 2563 | + if ( ! class_exists($this->value)) |
|
| 2564 | 2564 | { |
| 2565 | 2565 | $message = $message ?: $this->overrideError; |
| 2566 | 2566 | $message = sprintf( |
@@ -2582,14 +2582,14 @@ discard block |
||
| 2582 | 2582 | * @throws AssertionFailedException |
| 2583 | 2583 | * @throws \ReflectionException |
| 2584 | 2584 | */ |
| 2585 | - public function implementsInterface(string $interfaceName, string $message='', string $fieldName='') : Assert |
|
| 2585 | + public function implementsInterface(string $interfaceName, string $message = '', string $fieldName = '') : Assert |
|
| 2586 | 2586 | { |
| 2587 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2587 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2588 | 2588 | { |
| 2589 | 2589 | return $this; |
| 2590 | 2590 | } |
| 2591 | 2591 | $reflection = new \ReflectionClass($this->value); |
| 2592 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
| 2592 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
| 2593 | 2593 | { |
| 2594 | 2594 | $message = $message ?: $this->overrideError; |
| 2595 | 2595 | $message = sprintf( |
@@ -2598,7 +2598,7 @@ discard block |
||
| 2598 | 2598 | $this->stringify($interfaceName) |
| 2599 | 2599 | ); |
| 2600 | 2600 | |
| 2601 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, ['interface' => $interfaceName]); |
|
| 2601 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, [ 'interface' => $interfaceName ]); |
|
| 2602 | 2602 | } |
| 2603 | 2603 | |
| 2604 | 2604 | return $this; |
@@ -2618,13 +2618,13 @@ discard block |
||
| 2618 | 2618 | * @return Assert |
| 2619 | 2619 | * @throws AssertionFailedException |
| 2620 | 2620 | */ |
| 2621 | - public function isJsonString(string $message='', string $fieldName='') : Assert |
|
| 2621 | + public function isJsonString(string $message = '', string $fieldName = '') : Assert |
|
| 2622 | 2622 | { |
| 2623 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2623 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2624 | 2624 | { |
| 2625 | 2625 | return $this; |
| 2626 | 2626 | } |
| 2627 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
| 2627 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
| 2628 | 2628 | { |
| 2629 | 2629 | $message = $message ?: $this->overrideError; |
| 2630 | 2630 | $message = sprintf( |
@@ -2648,18 +2648,18 @@ discard block |
||
| 2648 | 2648 | * @return Assert |
| 2649 | 2649 | * @throws AssertionFailedException |
| 2650 | 2650 | */ |
| 2651 | - public function uuid(string $message='', string $fieldName='') : Assert |
|
| 2651 | + public function uuid(string $message = '', string $fieldName = '') : Assert |
|
| 2652 | 2652 | { |
| 2653 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2653 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2654 | 2654 | { |
| 2655 | 2655 | return $this; |
| 2656 | 2656 | } |
| 2657 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
| 2658 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
| 2657 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
| 2658 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
| 2659 | 2659 | { |
| 2660 | 2660 | return $this; |
| 2661 | 2661 | } |
| 2662 | - 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) ) |
|
| 2662 | + 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)) |
|
| 2663 | 2663 | { |
| 2664 | 2664 | $message = $message ?: $this->overrideError; |
| 2665 | 2665 | $message = sprintf( |
@@ -2688,13 +2688,13 @@ discard block |
||
| 2688 | 2688 | * @return Assert |
| 2689 | 2689 | * @throws AssertionFailedException |
| 2690 | 2690 | */ |
| 2691 | - public function samAccountName(string $message='', string $fieldName='') : Assert |
|
| 2691 | + public function samAccountName(string $message = '', string $fieldName = '') : Assert |
|
| 2692 | 2692 | { |
| 2693 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2693 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2694 | 2694 | { |
| 2695 | 2695 | return $this; |
| 2696 | 2696 | } |
| 2697 | - if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2697 | + if ( ! preg_match('/^([a-z0-9]{4,20})$/', $this->value)) |
|
| 2698 | 2698 | { |
| 2699 | 2699 | $message = $message ?: $this->overrideError; |
| 2700 | 2700 | $message = sprintf( |
@@ -2716,9 +2716,9 @@ discard block |
||
| 2716 | 2716 | * @return Assert |
| 2717 | 2717 | * @throws AssertionFailedException |
| 2718 | 2718 | */ |
| 2719 | - public function userPrincipalName(string $message='', string $fieldName='') : Assert |
|
| 2719 | + public function userPrincipalName(string $message = '', string $fieldName = '') : Assert |
|
| 2720 | 2720 | { |
| 2721 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2721 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2722 | 2722 | { |
| 2723 | 2723 | return $this; |
| 2724 | 2724 | } |
@@ -2751,13 +2751,13 @@ discard block |
||
| 2751 | 2751 | * @return Assert |
| 2752 | 2752 | * @throws AssertionFailedException |
| 2753 | 2753 | */ |
| 2754 | - public function isni(string $message='', string $fieldName='') |
|
| 2754 | + public function isni(string $message = '', string $fieldName = '') |
|
| 2755 | 2755 | { |
| 2756 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2756 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2757 | 2757 | { |
| 2758 | 2758 | return $this; |
| 2759 | 2759 | } |
| 2760 | - if ( !preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value) ) |
|
| 2760 | + if ( ! preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value)) |
|
| 2761 | 2761 | { |
| 2762 | 2762 | $message = $message ?: $this->overrideError; |
| 2763 | 2763 | $message = sprintf( |
@@ -2780,13 +2780,13 @@ discard block |
||
| 2780 | 2780 | * @return Assert |
| 2781 | 2781 | * @throws AssertionFailedException |
| 2782 | 2782 | */ |
| 2783 | - public function count(int $count, string $message='', string $fieldName='') : Assert |
|
| 2783 | + public function count(int $count, string $message = '', string $fieldName = '') : Assert |
|
| 2784 | 2784 | { |
| 2785 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2785 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2786 | 2786 | { |
| 2787 | 2787 | return $this; |
| 2788 | 2788 | } |
| 2789 | - if ( $count !== count($this->value) ) |
|
| 2789 | + if ($count !== count($this->value)) |
|
| 2790 | 2790 | { |
| 2791 | 2791 | $message = $message ?: $this->overrideError; |
| 2792 | 2792 | $message = sprintf( |
@@ -2795,7 +2795,7 @@ discard block |
||
| 2795 | 2795 | $this->stringify($count) |
| 2796 | 2796 | ); |
| 2797 | 2797 | |
| 2798 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, ['count' => $count]); |
|
| 2798 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, [ 'count' => $count ]); |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | return $this; |
@@ -2809,25 +2809,25 @@ discard block |
||
| 2809 | 2809 | */ |
| 2810 | 2810 | protected function doAllOrNullOr($func, $args) : bool |
| 2811 | 2811 | { |
| 2812 | - if ( $this->nullOr && is_null($this->value) ) |
|
| 2812 | + if ($this->nullOr && is_null($this->value)) |
|
| 2813 | 2813 | { |
| 2814 | 2814 | return true; |
| 2815 | 2815 | } |
| 2816 | - if ( $this->emptyOr && empty($this->value) ) |
|
| 2816 | + if ($this->emptyOr && empty($this->value)) |
|
| 2817 | 2817 | { |
| 2818 | 2818 | return true; |
| 2819 | 2819 | } |
| 2820 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
| 2820 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
| 2821 | 2821 | { |
| 2822 | - foreach ( $this->value as $idx => $value ) |
|
| 2822 | + foreach ($this->value as $idx => $value) |
|
| 2823 | 2823 | { |
| 2824 | 2824 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
| 2825 | - call_user_func_array([$object, $func], $args); |
|
| 2825 | + call_user_func_array([ $object, $func ], $args); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | return true; |
| 2828 | 2828 | } |
| 2829 | 2829 | |
| 2830 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
| 2830 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
| 2831 | 2831 | } |
| 2832 | 2832 | |
| 2833 | 2833 | /** |
@@ -2839,14 +2839,14 @@ discard block |
||
| 2839 | 2839 | * @return Assert |
| 2840 | 2840 | * @throws AssertionFailedException |
| 2841 | 2841 | */ |
| 2842 | - public function choicesNotEmpty(array $choices, string $message='', string $fieldName='') : Assert |
|
| 2842 | + public function choicesNotEmpty(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 2843 | 2843 | { |
| 2844 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2844 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2845 | 2845 | { |
| 2846 | 2846 | return $this; |
| 2847 | 2847 | } |
| 2848 | 2848 | $this->notEmpty($message, $fieldName); |
| 2849 | - foreach ( $choices as $choice ) |
|
| 2849 | + foreach ($choices as $choice) |
|
| 2850 | 2850 | { |
| 2851 | 2851 | $this->notEmptyKey($choice, $message, $fieldName); |
| 2852 | 2852 | } |
@@ -2863,14 +2863,14 @@ discard block |
||
| 2863 | 2863 | * @return Assert |
| 2864 | 2864 | * @throws AssertionFailedException |
| 2865 | 2865 | */ |
| 2866 | - public function methodExists($object, string $message='', string $fieldName='') : Assert |
|
| 2866 | + public function methodExists($object, string $message = '', string $fieldName = '') : Assert |
|
| 2867 | 2867 | { |
| 2868 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2868 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2869 | 2869 | { |
| 2870 | 2870 | return $this; |
| 2871 | 2871 | } |
| 2872 | 2872 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $fieldName); |
| 2873 | - if ( !method_exists($object, $this->value) ) |
|
| 2873 | + if ( ! method_exists($object, $this->value)) |
|
| 2874 | 2874 | { |
| 2875 | 2875 | $message = $message ?: $this->overrideError; |
| 2876 | 2876 | $message = sprintf( |
@@ -2892,13 +2892,13 @@ discard block |
||
| 2892 | 2892 | * @return Assert |
| 2893 | 2893 | * @throws AssertionFailedException |
| 2894 | 2894 | */ |
| 2895 | - public function isObject(string $message='', string $fieldName='') : Assert |
|
| 2895 | + public function isObject(string $message = '', string $fieldName = '') : Assert |
|
| 2896 | 2896 | { |
| 2897 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2897 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2898 | 2898 | { |
| 2899 | 2899 | return $this; |
| 2900 | 2900 | } |
| 2901 | - if ( !is_object($this->value) ) |
|
| 2901 | + if ( ! is_object($this->value)) |
|
| 2902 | 2902 | { |
| 2903 | 2903 | $message = $message ?: $this->overrideError; |
| 2904 | 2904 | $message = sprintf( |
@@ -2920,33 +2920,33 @@ discard block |
||
| 2920 | 2920 | */ |
| 2921 | 2921 | private function stringify($value) : string |
| 2922 | 2922 | { |
| 2923 | - if ( is_bool($value) ) |
|
| 2923 | + if (is_bool($value)) |
|
| 2924 | 2924 | { |
| 2925 | 2925 | return $value ? '<TRUE>' : '<FALSE>'; |
| 2926 | 2926 | } |
| 2927 | - if ( is_scalar($value) ) |
|
| 2927 | + if (is_scalar($value)) |
|
| 2928 | 2928 | { |
| 2929 | 2929 | $val = (string)$value; |
| 2930 | - if ( strlen($val) > 100 ) |
|
| 2930 | + if (strlen($val) > 100) |
|
| 2931 | 2931 | { |
| 2932 | - $val = substr($val, 0, 97) . '...'; |
|
| 2932 | + $val = substr($val, 0, 97).'...'; |
|
| 2933 | 2933 | } |
| 2934 | 2934 | |
| 2935 | 2935 | return $val; |
| 2936 | 2936 | } |
| 2937 | - if ( is_array($value) ) |
|
| 2937 | + if (is_array($value)) |
|
| 2938 | 2938 | { |
| 2939 | 2939 | return '<ARRAY>'; |
| 2940 | 2940 | } |
| 2941 | - if ( is_object($value) ) |
|
| 2941 | + if (is_object($value)) |
|
| 2942 | 2942 | { |
| 2943 | 2943 | return get_class($value); |
| 2944 | 2944 | } |
| 2945 | - if ( is_resource($value) ) |
|
| 2945 | + if (is_resource($value)) |
|
| 2946 | 2946 | { |
| 2947 | 2947 | return '<RESOURCE>'; |
| 2948 | 2948 | } |
| 2949 | - if ( $value === null ) |
|
| 2949 | + if ($value === null) |
|
| 2950 | 2950 | { |
| 2951 | 2951 | return '<NULL>'; |
| 2952 | 2952 | } |
@@ -158,8 +158,7 @@ discard block |
||
| 158 | 158 | try |
| 159 | 159 | { |
| 160 | 160 | $validator->__invoke(); |
| 161 | - } |
|
| 162 | - catch ( AssertionFailedException $e ) |
|
| 161 | + } catch ( AssertionFailedException $e ) |
|
| 163 | 162 | { |
| 164 | 163 | $errors[$fieldName] = $e->getMessage(); |
| 165 | 164 | } |
@@ -2250,8 +2249,7 @@ discard block |
||
| 2250 | 2249 | ); |
| 2251 | 2250 | |
| 2252 | 2251 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_EMAIL, $fieldName); |
| 2253 | - } |
|
| 2254 | - else |
|
| 2252 | + } else |
|
| 2255 | 2253 | { |
| 2256 | 2254 | $host = substr($this->value, strpos($this->value, '@') + 1); |
| 2257 | 2255 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
@@ -2385,8 +2383,7 @@ discard block |
||
| 2385 | 2383 | try |
| 2386 | 2384 | { |
| 2387 | 2385 | $this->regex('/^04([0-9]{8})$/', $message, $fieldName); |
| 2388 | - } |
|
| 2389 | - catch ( AssertionFailedException $e ) |
|
| 2386 | + } catch ( AssertionFailedException $e ) |
|
| 2390 | 2387 | { |
| 2391 | 2388 | $message = $message ?: $this->overrideError; |
| 2392 | 2389 | $message = sprintf( |
@@ -2418,8 +2415,7 @@ discard block |
||
| 2418 | 2415 | try |
| 2419 | 2416 | { |
| 2420 | 2417 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName); |
| 2421 | - } |
|
| 2422 | - catch (AssertionFailedException $e) |
|
| 2418 | + } catch (AssertionFailedException $e) |
|
| 2423 | 2419 | { |
| 2424 | 2420 | $message = $message ?: $this->overrideError; |
| 2425 | 2421 | $message = sprintf( |
@@ -2725,8 +2721,7 @@ discard block |
||
| 2725 | 2721 | try |
| 2726 | 2722 | { |
| 2727 | 2723 | $this->email($message, $fieldName); |
| 2728 | - } |
|
| 2729 | - catch (AssertionFailedException $e) |
|
| 2724 | + } catch (AssertionFailedException $e) |
|
| 2730 | 2725 | { |
| 2731 | 2726 | $message = $message ?: $this->overrideError; |
| 2732 | 2727 | $message = sprintf( |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param Closure $test |
| 43 | 43 | * @param string $suiteName |
| 44 | 44 | * @param string $successMessage |
| 45 | - * @param int|null $exceptionCode |
|
| 45 | + * @param integer $exceptionCode |
|
| 46 | 46 | * @param string $exceptionClass |
| 47 | 47 | * @param string $exceptionMsg |
| 48 | 48 | * @return Suite |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * @param string $testName |
| 434 | 434 | * @param Closure $test |
| 435 | 435 | * @param string $successMessage |
| 436 | - * @param int|null $exceptionCode |
|
| 436 | + * @param integer $exceptionCode |
|
| 437 | 437 | * @param string $exceptionClass |
| 438 | 438 | * @return Suite |
| 439 | 439 | * @throws AssertionFailedException |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | /** |
| 1015 | 1015 | * Log messages to resource |
| 1016 | 1016 | * |
| 1017 | - * @param mixed $level The level of the log message |
|
| 1017 | + * @param string $level The level of the log message |
|
| 1018 | 1018 | * @param string $message If an object is passed it must implement __toString() |
| 1019 | 1019 | * @param array $context Placeholders to be substituted in the message |
| 1020 | 1020 | */ |
@@ -1091,7 +1091,7 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | /** |
| 1094 | - * @return mixed|resource |
|
| 1094 | + * @return resource |
|
| 1095 | 1095 | * @throws \Exception |
| 1096 | 1096 | */ |
| 1097 | 1097 | protected function getResource() |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | protected static $currentSuite = self::DEFAULT_SUITE; |
| 13 | 13 | |
| 14 | 14 | /** @var Suite[] */ |
| 15 | - protected static $suites = []; |
|
| 15 | + protected static $suites = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | /** @var Logger $logger */ |
| 18 | 18 | public static $logger = null; |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * @param string $name |
| 30 | 30 | * @return Suite |
| 31 | 31 | */ |
| 32 | - public static function suite(string $name='') : Suite |
|
| 32 | + public static function suite(string $name = '') : Suite |
|
| 33 | 33 | { |
| 34 | 34 | $name = $name ?: static::$currentSuite; |
| 35 | - static::$suites[$name] = new Suite(); |
|
| 35 | + static::$suites[ $name ] = new Suite(); |
|
| 36 | 36 | |
| 37 | - return static::$suites[$name]; |
|
| 37 | + return static::$suites[ $name ]; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return Suite |
| 49 | 49 | * @throws AssertionFailedException |
| 50 | 50 | */ |
| 51 | - public static function test(string $testName, Closure $test, string $suiteName='', string $successMessage='', int $exceptionCode=0, string $exceptionClass='', string $exceptionMsg='') : Suite |
|
| 51 | + public static function test(string $testName, Closure $test, string $suiteName = '', string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '', string $exceptionMsg = '') : Suite |
|
| 52 | 52 | { |
| 53 | 53 | Assert::that($successMessage)->notEmpty(); |
| 54 | 54 | Assert::that($test)->isCallable(); |
@@ -62,17 +62,17 @@ discard block |
||
| 62 | 62 | * @param string $testName |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public static function run(string $suiteName='', string $testName='') : array |
|
| 65 | + public static function run(string $suiteName = '', string $testName = '') : array |
|
| 66 | 66 | { |
| 67 | 67 | $totalFailed = 0; |
| 68 | 68 | $totalTests = 0; |
| 69 | 69 | $suites = static::$suites; |
| 70 | - if ( ! empty($suiteName) ) |
|
| 70 | + if ( ! empty($suiteName)) |
|
| 71 | 71 | { |
| 72 | 72 | Assert::that($suites)->keyExists($suiteName, "The test suite ({$suiteName}) has not been loaded"); |
| 73 | - $suites = [$suites[$suiteName]]; |
|
| 73 | + $suites = [ $suites[ $suiteName ] ]; |
|
| 74 | 74 | } |
| 75 | - foreach ( $suites as $suite ) |
|
| 75 | + foreach ($suites as $suite) |
|
| 76 | 76 | { |
| 77 | 77 | $totalFailed += $suite->run($testName); |
| 78 | 78 | $totalTests += $suite->totalTestsCount(); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public static function getLogger() : Logger |
| 88 | 88 | { |
| 89 | - if ( ! static::$logger ) |
|
| 89 | + if ( ! static::$logger) |
|
| 90 | 90 | { |
| 91 | 91 | static::$logger = new Logger(); |
| 92 | 92 | } |
@@ -98,15 +98,15 @@ discard block |
||
| 98 | 98 | * @param string $suiteName |
| 99 | 99 | * @return Suite |
| 100 | 100 | */ |
| 101 | - protected static function getSuite(string $suiteName='') : Suite |
|
| 101 | + protected static function getSuite(string $suiteName = '') : Suite |
|
| 102 | 102 | { |
| 103 | - $suiteName = $suiteName ?: static::$currentSuite; |
|
| 104 | - if ( ! array_key_exists($suiteName, static::$suites) ) |
|
| 103 | + $suiteName = $suiteName ?: static::$currentSuite; |
|
| 104 | + if ( ! array_key_exists($suiteName, static::$suites)) |
|
| 105 | 105 | { |
| 106 | 106 | return static::suite($suiteName); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - return static::$suites[$suiteName]; |
|
| 109 | + return static::$suites[ $suiteName ]; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -122,22 +122,22 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | $className = array_values(array_diff_key(get_declared_classes(), $declaredClasses)); |
| 124 | 124 | |
| 125 | - $reflectionClass = new \ReflectionClass($className[0]); |
|
| 125 | + $reflectionClass = new \ReflectionClass($className[ 0 ]); |
|
| 126 | 126 | $publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC); |
| 127 | 127 | $fullClassName = $reflectionClass->getName(); |
| 128 | 128 | $className = $reflectionClass->getShortName(); |
| 129 | 129 | $namespace = $reflectionClass->getNamespaceName(); |
| 130 | 130 | $constructorParams = ''; |
| 131 | - foreach ( $publicMethods as $method ) |
|
| 131 | + foreach ($publicMethods as $method) |
|
| 132 | 132 | { |
| 133 | - if ( $method->isConstructor() ) |
|
| 133 | + if ($method->isConstructor()) |
|
| 134 | 134 | { |
| 135 | - $constructorParams = static::getMethodParams($method); |
|
| 135 | + $constructorParams = static::getMethodParams($method); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | $objectInit = "new {$fullClassName}({$constructorParams})"; |
| 139 | - $output = []; |
|
| 140 | - $output[] = <<<PHP |
|
| 139 | + $output = [ ]; |
|
| 140 | + $output[ ] = <<<PHP |
|
| 141 | 141 | <?php declare(strict_types=1); |
| 142 | 142 | |
| 143 | 143 | namespace {$namespace}\Test; |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | ->fixture('testSubject', {$objectInit}) |
| 152 | 152 | PHP; |
| 153 | 153 | |
| 154 | - foreach ( $publicMethods as $method ) |
|
| 154 | + foreach ($publicMethods as $method) |
|
| 155 | 155 | { |
| 156 | 156 | $methodName = $method->getName(); |
| 157 | 157 | $methodParams = static::getMethodParams($method); |
| 158 | - $testName = 'test' . ucfirst($methodName); |
|
| 158 | + $testName = 'test'.ucfirst($methodName); |
|
| 159 | 159 | $successArgs = static::getMethodArgs($method); |
| 160 | 160 | $failArgs = static::getMethodArgs($method, ' '); |
| 161 | 161 | $returnVal = static::getReturnVal($method); |
| 162 | 162 | $methodSignature = "\$suite->getFixture('testSubject')->{$methodName}({$methodParams})"; |
| 163 | 163 | |
| 164 | - if ( $method->isStatic() ) |
|
| 164 | + if ($method->isStatic()) |
|
| 165 | 165 | { |
| 166 | 166 | $methodSignature = "{$className}::{$methodName}({$methodParams})"; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $output[] = <<<PHP |
|
| 169 | + $output[ ] = <<<PHP |
|
| 170 | 170 | |
| 171 | 171 | ->test('{$testName}Success', function(Suite \$suite) { |
| 172 | 172 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $output[] = " ;"; |
|
| 193 | + $output[ ] = " ;"; |
|
| 194 | 194 | |
| 195 | 195 | return static::createDirectoriesAndSaveFile($outputPath, implode("\n", $output)); |
| 196 | 196 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param int $dirMode |
| 204 | 204 | * @return bool |
| 205 | 205 | */ |
| 206 | - protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags=0, $dirMode=0755) : bool |
|
| 206 | + protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags = 0, $dirMode = 0755) : bool |
|
| 207 | 207 | { |
| 208 | 208 | static::createParentDirectories($filePath, $dirMode); |
| 209 | 209 | Assert::that(file_put_contents($filePath, $data, $flags))->notFalse("Failed to put contents in file ({$filePath})"); |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | * @param int $mode |
| 217 | 217 | * @return bool |
| 218 | 218 | */ |
| 219 | - protected static function createParentDirectories(string $filePath, $mode=0755) : bool |
|
| 219 | + protected static function createParentDirectories(string $filePath, $mode = 0755) : bool |
|
| 220 | 220 | { |
| 221 | - $directoryPath = preg_match('/.*\//', $filePath); |
|
| 221 | + $directoryPath = preg_match('/.*\//', $filePath); |
|
| 222 | 222 | Assert::that($filePath) |
| 223 | 223 | ->notEmpty("Failed to identify path ({$directoryPath}) to create") |
| 224 | 224 | ->notEq(DIRECTORY_SEPARATOR, "Failed to identify path ({$directoryPath}) to create"); |
| 225 | - if ( file_exists($directoryPath) ) |
|
| 225 | + if (file_exists($directoryPath)) |
|
| 226 | 226 | { |
| 227 | 227 | Assert::that(is_dir($directoryPath))->notFalse("Failed to create parent directories.. files exists and is not a directory({$directoryPath})"); |
| 228 | 228 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | protected static function getMethodParams(\ReflectionMethod $method) : string |
| 242 | 242 | { |
| 243 | - $output = []; |
|
| 244 | - foreach ( $method->getParameters() as $param ) |
|
| 243 | + $output = [ ]; |
|
| 244 | + foreach ($method->getParameters() as $param) |
|
| 245 | 245 | { |
| 246 | - $output[] = '$' . $param->getName(); |
|
| 246 | + $output[ ] = '$'.$param->getName(); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | return implode(', ', $output); |
@@ -254,16 +254,16 @@ discard block |
||
| 254 | 254 | * @param string $extraPadding |
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | - protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding='') : string |
|
| 257 | + protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding = '') : string |
|
| 258 | 258 | { |
| 259 | - $output = []; |
|
| 259 | + $output = [ ]; |
|
| 260 | 260 | $params = $method->getParameters(); |
| 261 | - foreach ( $params as $param ) |
|
| 261 | + foreach ($params as $param) |
|
| 262 | 262 | { |
| 263 | 263 | $type = $param->hasType() ? $param->getType()->_toString() : ''; |
| 264 | - $paramDef = str_pad('$' . $param->getName(), 32, ' ') . '= '; |
|
| 265 | - $paramDef .= static::getDefaultValue($type); |
|
| 266 | - $output[] = $paramDef . ';'; |
|
| 264 | + $paramDef = str_pad('$'.$param->getName(), 32, ' ').'= '; |
|
| 265 | + $paramDef .= static::getDefaultValue($type); |
|
| 266 | + $output[ ] = $paramDef.';'; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | return implode("\n {$extraPadding}", $output); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | protected static function getReturnVal(\ReflectionMethod $method) : string |
| 277 | 277 | { |
| 278 | - $returnType = $method->hasReturnType() ? $method->getReturnType()->_toString() : ''; |
|
| 278 | + $returnType = $method->hasReturnType() ? $method->getReturnType()->_toString() : ''; |
|
| 279 | 279 | |
| 280 | 280 | return static::getDefaultValue($returnType); |
| 281 | 281 | } |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | * @param string $default |
| 286 | 286 | * @return string |
| 287 | 287 | */ |
| 288 | - protected static function getDefaultValue(string $type='', string $default='null') : string |
|
| 288 | + protected static function getDefaultValue(string $type = '', string $default = 'null') : string |
|
| 289 | 289 | { |
| 290 | - $typeMap = [ |
|
| 290 | + $typeMap = [ |
|
| 291 | 291 | 'int' => "0", |
| 292 | 292 | 'float' => "0.0", |
| 293 | 293 | 'string' => "''", |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | 'array' => "[]", |
| 297 | 297 | ]; |
| 298 | 298 | |
| 299 | - return $typeMap[$type] ?? $default; |
|
| 299 | + return $typeMap[ $type ] ?? $default; |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
@@ -304,16 +304,16 @@ discard block |
||
| 304 | 304 | class Suite |
| 305 | 305 | { |
| 306 | 306 | /** @var Closure[] */ |
| 307 | - protected $setUps = []; |
|
| 307 | + protected $setUps = [ ]; |
|
| 308 | 308 | |
| 309 | 309 | /** @var Closure[] */ |
| 310 | - protected $tearDowns = []; |
|
| 310 | + protected $tearDowns = [ ]; |
|
| 311 | 311 | |
| 312 | 312 | /** @var Test[] */ |
| 313 | - protected $tests = []; |
|
| 313 | + protected $tests = [ ]; |
|
| 314 | 314 | |
| 315 | 315 | /** @var mixed[] */ |
| 316 | - protected $fixtures = []; |
|
| 316 | + protected $fixtures = [ ]; |
|
| 317 | 317 | |
| 318 | 318 | /** @var Logger */ |
| 319 | 319 | protected $logger = null; |
@@ -325,30 +325,30 @@ discard block |
||
| 325 | 325 | * @param string $filter |
| 326 | 326 | * @return int |
| 327 | 327 | */ |
| 328 | - public function run(string $filter='') : int |
|
| 328 | + public function run(string $filter = '') : int |
|
| 329 | 329 | { |
| 330 | - foreach ( $this->tests as $test => $testCase ) |
|
| 330 | + foreach ($this->tests as $test => $testCase) |
|
| 331 | 331 | { |
| 332 | - $testName = $testCase->getTestName(); |
|
| 333 | - if ( $filter && $testName !== $filter ) |
|
| 332 | + $testName = $testCase->getTestName(); |
|
| 333 | + if ($filter && $testName !== $filter) |
|
| 334 | 334 | { |
| 335 | 335 | continue; |
| 336 | 336 | } |
| 337 | 337 | try |
| 338 | 338 | { |
| 339 | 339 | $this->getLogger()->info("[{$testName}] - Starting..."); |
| 340 | - foreach ( $this->setUps as $idx => $closure ) |
|
| 340 | + foreach ($this->setUps as $idx => $closure) |
|
| 341 | 341 | { |
| 342 | 342 | $closure->__invoke($this); |
| 343 | 343 | } |
| 344 | 344 | $testCase->runTest($this); |
| 345 | - foreach ( $this->tearDowns as $idx => $closure ) |
|
| 345 | + foreach ($this->tearDowns as $idx => $closure) |
|
| 346 | 346 | { |
| 347 | 347 | $closure->__invoke($this); |
| 348 | 348 | } |
| 349 | - $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); |
|
| 349 | + $this->getLogger()->info("[{$testName}] - ".$testCase->getSuccessMessage()); |
|
| 350 | 350 | } |
| 351 | - catch ( \Exception $e ) |
|
| 351 | + catch (\Exception $e) |
|
| 352 | 352 | { |
| 353 | 353 | $expectedCode = $testCase->getExceptionCode(); |
| 354 | 354 | $expectedClass = $testCase->getExceptionType(); |
@@ -356,35 +356,35 @@ discard block |
||
| 356 | 356 | $code = $e->getCode(); |
| 357 | 357 | $message = $e->getMessage(); |
| 358 | 358 | $exception = get_class($e); |
| 359 | - if ( ! $expectedClass && ! $expectedCode ) |
|
| 359 | + if ( ! $expectedClass && ! $expectedCode) |
|
| 360 | 360 | { |
| 361 | - $this->getLogger()->error($e->getMessage(), [compact('testName'), $e]); |
|
| 361 | + $this->getLogger()->error($e->getMessage(), [ compact('testName'), $e ]); |
|
| 362 | 362 | $this->failedCount++; |
| 363 | 363 | |
| 364 | 364 | continue; |
| 365 | 365 | } |
| 366 | - if ( $expectedCode && $expectedCode !== $code ) |
|
| 366 | + if ($expectedCode && $expectedCode !== $code) |
|
| 367 | 367 | { |
| 368 | - $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [compact('testName'), $e]); |
|
| 368 | + $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [ compact('testName'), $e ]); |
|
| 369 | 369 | $this->failedCount++; |
| 370 | 370 | |
| 371 | 371 | continue; |
| 372 | 372 | } |
| 373 | - if ( $expectedMsg && $expectedMsg !== $message ) |
|
| 373 | + if ($expectedMsg && $expectedMsg !== $message) |
|
| 374 | 374 | { |
| 375 | - $this->getLogger()->error("Exception message({$message}) was expected to be ({$expectedMsg})", [compact('testName'), $e]); |
|
| 375 | + $this->getLogger()->error("Exception message({$message}) was expected to be ({$expectedMsg})", [ compact('testName'), $e ]); |
|
| 376 | 376 | $this->failedCount++; |
| 377 | 377 | |
| 378 | 378 | continue; |
| 379 | 379 | } |
| 380 | - if ( $expectedClass && $expectedClass !== $exception ) |
|
| 380 | + if ($expectedClass && $expectedClass !== $exception) |
|
| 381 | 381 | { |
| 382 | - $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [compact('testName'), $e]); |
|
| 382 | + $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [ compact('testName'), $e ]); |
|
| 383 | 383 | $this->failedCount++; |
| 384 | 384 | |
| 385 | 385 | continue; |
| 386 | 386 | } |
| 387 | - $this->getLogger()->info("[{$test}] - " . $testCase->getSuccessMessage()); |
|
| 387 | + $this->getLogger()->info("[{$test}] - ".$testCase->getSuccessMessage()); |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | public function setUp(Closure $callback) : Suite |
| 415 | 415 | { |
| 416 | - $this->setUps[] = $callback; |
|
| 416 | + $this->setUps[ ] = $callback; |
|
| 417 | 417 | |
| 418 | 418 | return $this; |
| 419 | 419 | } |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public function tearDown(Closure $callback) : Suite |
| 426 | 426 | { |
| 427 | - $this->tearDowns[] = $callback; |
|
| 427 | + $this->tearDowns[ ] = $callback; |
|
| 428 | 428 | |
| 429 | 429 | return $this; |
| 430 | 430 | } |
@@ -438,9 +438,9 @@ discard block |
||
| 438 | 438 | * @return Suite |
| 439 | 439 | * @throws AssertionFailedException |
| 440 | 440 | */ |
| 441 | - public function test(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='', string $exceptionMsg='') : Suite |
|
| 441 | + public function test(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '', string $exceptionMsg = '') : Suite |
|
| 442 | 442 | { |
| 443 | - $this->tests[] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass, $exceptionMsg); |
|
| 443 | + $this->tests[ ] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass, $exceptionMsg); |
|
| 444 | 444 | |
| 445 | 445 | return $this; |
| 446 | 446 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | public function fixture(string $fixtureName, $value) : Suite |
| 454 | 454 | { |
| 455 | - $this->fixtures[$fixtureName] = $value; |
|
| 455 | + $this->fixtures[ $fixtureName ] = $value; |
|
| 456 | 456 | |
| 457 | 457 | return $this; |
| 458 | 458 | } |
@@ -466,12 +466,12 @@ discard block |
||
| 466 | 466 | { |
| 467 | 467 | Assert::that($this->fixtures)->keyExists($fixtureName, "The fixture ({$fixtureName}) does not exist."); |
| 468 | 468 | |
| 469 | - if ( is_callable($this->fixtures[$fixtureName]) ) |
|
| 469 | + if (is_callable($this->fixtures[ $fixtureName ])) |
|
| 470 | 470 | { |
| 471 | - $this->fixtures[$fixtureName] = $this->fixtures[$fixtureName]->__invoke($this); |
|
| 471 | + $this->fixtures[ $fixtureName ] = $this->fixtures[ $fixtureName ]->__invoke($this); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - return $this->fixtures[$fixtureName]; |
|
| 474 | + return $this->fixtures[ $fixtureName ]; |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | public function setLogger(Logger $logger) : Suite |
| 493 | 493 | { |
| 494 | - $this->logger = $logger; |
|
| 494 | + $this->logger = $logger; |
|
| 495 | 495 | |
| 496 | 496 | return $this; |
| 497 | 497 | } |
@@ -501,9 +501,9 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | public function getLogger() : Logger |
| 503 | 503 | { |
| 504 | - if ( ! $this->logger ) |
|
| 504 | + if ( ! $this->logger) |
|
| 505 | 505 | { |
| 506 | - $this->logger = new Logger(); |
|
| 506 | + $this->logger = new Logger(); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | return $this->logger; |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @param string $exceptionMsg |
| 543 | 543 | * @throws AssertionFailedException |
| 544 | 544 | */ |
| 545 | - public function __construct(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='', string $exceptionMsg='') |
|
| 545 | + public function __construct(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '', string $exceptionMsg = '') |
|
| 546 | 546 | { |
| 547 | 547 | $this->setTestName($testName); |
| 548 | 548 | $this->setTest($test); |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | { |
| 569 | 569 | Assert::that($testName)->notEmpty(); |
| 570 | 570 | |
| 571 | - $this->testName = $testName; |
|
| 571 | + $this->testName = $testName; |
|
| 572 | 572 | |
| 573 | 573 | return $this; |
| 574 | 574 | } |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | */ |
| 579 | 579 | public function getSuccessMessage() : string |
| 580 | 580 | { |
| 581 | - if ( ! $this->successMessage ) |
|
| 581 | + if ( ! $this->successMessage) |
|
| 582 | 582 | { |
| 583 | 583 | return "Successfully run {$this->testName}"; |
| 584 | 584 | } |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | */ |
| 594 | 594 | public function setSuccessMessage(string $successMessage) : Test |
| 595 | 595 | { |
| 596 | - $this->successMessage = $successMessage; |
|
| 596 | + $this->successMessage = $successMessage; |
|
| 597 | 597 | |
| 598 | 598 | return $this; |
| 599 | 599 | } |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | */ |
| 613 | 613 | public function setTest(Closure $test) : Test |
| 614 | 614 | { |
| 615 | - $this->test = $test; |
|
| 615 | + $this->test = $test; |
|
| 616 | 616 | |
| 617 | 617 | return $this; |
| 618 | 618 | } |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | */ |
| 632 | 632 | public function setExceptionType(string $exceptionType) : Test |
| 633 | 633 | { |
| 634 | - $this->exceptionType = $exceptionType; |
|
| 634 | + $this->exceptionType = $exceptionType; |
|
| 635 | 635 | |
| 636 | 636 | return $this; |
| 637 | 637 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | */ |
| 651 | 651 | public function setExceptionMsg(string $exceptionMsg) : Test |
| 652 | 652 | { |
| 653 | - $this->exceptionMsg = $exceptionMsg; |
|
| 653 | + $this->exceptionMsg = $exceptionMsg; |
|
| 654 | 654 | |
| 655 | 655 | return $this; |
| 656 | 656 | } |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | */ |
| 670 | 670 | public function setExceptionCode(int $exceptionCode) : Test |
| 671 | 671 | { |
| 672 | - $this->exceptionCode = $exceptionCode; |
|
| 672 | + $this->exceptionCode = $exceptionCode; |
|
| 673 | 673 | |
| 674 | 674 | return $this; |
| 675 | 675 | } |
@@ -750,21 +750,21 @@ discard block |
||
| 750 | 750 | /** |
| 751 | 751 | * @var array $logLevels List of supported levels |
| 752 | 752 | */ |
| 753 | - static protected $logLevels = [ |
|
| 754 | - self::EMERGENCY => [1, self::WHITE, self::RED, self::DEFAULT, 'EMERG'], |
|
| 755 | - self::ALERT => [2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT'], |
|
| 756 | - self::CRITICAL => [3, self::RED, self::DEFAULT, self::BOLD , 'CRIT'], |
|
| 757 | - self::ERROR => [4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR'], |
|
| 758 | - self::WARNING => [5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN'], |
|
| 759 | - self::NOTICE => [6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE'], |
|
| 760 | - self::INFO => [7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO'], |
|
| 761 | - self::DEBUG => [8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG'], |
|
| 753 | + static protected $logLevels = [ |
|
| 754 | + self::EMERGENCY => [ 1, self::WHITE, self::RED, self::DEFAULT, 'EMERG' ], |
|
| 755 | + self::ALERT => [ 2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT' ], |
|
| 756 | + self::CRITICAL => [ 3, self::RED, self::DEFAULT, self::BOLD, 'CRIT' ], |
|
| 757 | + self::ERROR => [ 4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR' ], |
|
| 758 | + self::WARNING => [ 5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN' ], |
|
| 759 | + self::NOTICE => [ 6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE' ], |
|
| 760 | + self::INFO => [ 7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO' ], |
|
| 761 | + self::DEBUG => [ 8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG' ], |
|
| 762 | 762 | ]; |
| 763 | 763 | |
| 764 | 764 | /** |
| 765 | 765 | * @var array |
| 766 | 766 | */ |
| 767 | - static protected $colours = [ |
|
| 767 | + static protected $colours = [ |
|
| 768 | 768 | 'fore' => [ |
| 769 | 769 | self::BLACK => '0;30', |
| 770 | 770 | self::DARK_GRAY => '1;30', |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | self::CYAN => '46', |
| 796 | 796 | self::LIGHT_GRAY => '47', |
| 797 | 797 | ], |
| 798 | - self::BOLD => [], |
|
| 798 | + self::BOLD => [ ], |
|
| 799 | 799 | ]; |
| 800 | 800 | |
| 801 | 801 | /** |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @param bool $gzipFile |
| 806 | 806 | * @param bool $addDate |
| 807 | 807 | */ |
| 808 | - public function __construct($resource=STDOUT, string $level=self::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true) |
|
| 808 | + public function __construct($resource = STDOUT, string $level = self::INFO, bool $useLocking = false, bool $gzipFile = false, bool $addDate = true) |
|
| 809 | 809 | { |
| 810 | 810 | $this->resource = $resource; |
| 811 | 811 | $this->setLogLevel($level); |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | * @param string $message |
| 821 | 821 | * @param array $context |
| 822 | 822 | */ |
| 823 | - public function emergency(string $message, array $context=[]) |
|
| 823 | + public function emergency(string $message, array $context = [ ]) |
|
| 824 | 824 | { |
| 825 | 825 | $this->log(self::EMERGENCY, $message, $context); |
| 826 | 826 | } |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | * @param string $message |
| 835 | 835 | * @param array $context |
| 836 | 836 | */ |
| 837 | - public function alert(string $message, array $context=[]) |
|
| 837 | + public function alert(string $message, array $context = [ ]) |
|
| 838 | 838 | { |
| 839 | 839 | $this->log(self::ALERT, $message, $context); |
| 840 | 840 | } |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | * @param string $message |
| 848 | 848 | * @param array $context |
| 849 | 849 | */ |
| 850 | - public function critical(string $message, array $context=[]) |
|
| 850 | + public function critical(string $message, array $context = [ ]) |
|
| 851 | 851 | { |
| 852 | 852 | $this->log(self::CRITICAL, $message, $context); |
| 853 | 853 | } |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | * @param string $message |
| 860 | 860 | * @param array $context |
| 861 | 861 | */ |
| 862 | - public function error(string $message, array $context=[]) |
|
| 862 | + public function error(string $message, array $context = [ ]) |
|
| 863 | 863 | { |
| 864 | 864 | $this->log(self::ERROR, $message, $context); |
| 865 | 865 | } |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * @param string $message |
| 874 | 874 | * @param array $context |
| 875 | 875 | */ |
| 876 | - public function warning(string $message, array $context=[]) |
|
| 876 | + public function warning(string $message, array $context = [ ]) |
|
| 877 | 877 | { |
| 878 | 878 | $this->log(self::WARNING, $message, $context); |
| 879 | 879 | } |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | * @param string $message |
| 885 | 885 | * @param array $context |
| 886 | 886 | */ |
| 887 | - public function notice(string $message, array $context=[]) |
|
| 887 | + public function notice(string $message, array $context = [ ]) |
|
| 888 | 888 | { |
| 889 | 889 | $this->log(self::NOTICE, $message, $context); |
| 890 | 890 | } |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | * @param string $message |
| 898 | 898 | * @param array $context |
| 899 | 899 | */ |
| 900 | - public function info(string $message, array $context=[]) |
|
| 900 | + public function info(string $message, array $context = [ ]) |
|
| 901 | 901 | { |
| 902 | 902 | $this->log(self::INFO, $message, $context); |
| 903 | 903 | } |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | * @param string $message |
| 909 | 909 | * @param array $context |
| 910 | 910 | */ |
| 911 | - public function debug(string $message, array $context=[]) |
|
| 911 | + public function debug(string $message, array $context = [ ]) |
|
| 912 | 912 | { |
| 913 | 913 | $this->log(self::DEBUG, $message, $context); |
| 914 | 914 | } |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | */ |
| 920 | 920 | public function setLogFile($resource) : Logger |
| 921 | 921 | { |
| 922 | - $this->resource = $resource; |
|
| 922 | + $this->resource = $resource; |
|
| 923 | 923 | |
| 924 | 924 | return $this; |
| 925 | 925 | } |
@@ -931,23 +931,23 @@ discard block |
||
| 931 | 931 | * @param bool $bold |
| 932 | 932 | * @return string |
| 933 | 933 | */ |
| 934 | - public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
| 934 | + public static function addColour(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
| 935 | 935 | { |
| 936 | 936 | // todo: support bold |
| 937 | 937 | unset($bold); |
| 938 | 938 | $coloredString = ''; |
| 939 | 939 | // Check if given foreground color found |
| 940 | - if ( isset(static::$colours['fore'][$foregroundColor]) ) |
|
| 940 | + if (isset(static::$colours[ 'fore' ][ $foregroundColor ])) |
|
| 941 | 941 | { |
| 942 | - $coloredString .= "\033[" . static::$colours['fore'][$foregroundColor] . "m"; |
|
| 942 | + $coloredString .= "\033[".static::$colours[ 'fore' ][ $foregroundColor ]."m"; |
|
| 943 | 943 | } |
| 944 | 944 | // Check if given background color found |
| 945 | - if ( isset(static::$colours['back'][$backgroundColor]) ) |
|
| 945 | + if (isset(static::$colours[ 'back' ][ $backgroundColor ])) |
|
| 946 | 946 | { |
| 947 | - $coloredString .= "\033[" . static::$colours['back'][$backgroundColor] . "m"; |
|
| 947 | + $coloredString .= "\033[".static::$colours[ 'back' ][ $backgroundColor ]."m"; |
|
| 948 | 948 | } |
| 949 | 949 | // Add string and end coloring |
| 950 | - $coloredString .= $string . "\033[0m"; |
|
| 950 | + $coloredString .= $string."\033[0m"; |
|
| 951 | 951 | |
| 952 | 952 | return $coloredString; |
| 953 | 953 | } |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * @param bool $bold |
| 960 | 960 | * @return string |
| 961 | 961 | */ |
| 962 | - public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
|
| 962 | + public function colourize(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string |
|
| 963 | 963 | { |
| 964 | 964 | return static::addColour($string, $foregroundColor, $backgroundColor, $bold); |
| 965 | 965 | } |
@@ -970,11 +970,11 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | public function setLogLevel(string $level) : Logger |
| 972 | 972 | { |
| 973 | - if ( ! isset(static::$logLevels[$level]) ) |
|
| 973 | + if ( ! isset(static::$logLevels[ $level ])) |
|
| 974 | 974 | { |
| 975 | 975 | throw new \InvalidArgumentException("Log level is invalid"); |
| 976 | 976 | } |
| 977 | - $this->level = static::$logLevels[$level][0]; |
|
| 977 | + $this->level = static::$logLevels[ $level ][ 0 ]; |
|
| 978 | 978 | |
| 979 | 979 | return $this; |
| 980 | 980 | } |
@@ -1018,25 +1018,25 @@ discard block |
||
| 1018 | 1018 | * @param string $message If an object is passed it must implement __toString() |
| 1019 | 1019 | * @param array $context Placeholders to be substituted in the message |
| 1020 | 1020 | */ |
| 1021 | - public function log($level, $message, array $context=[]) |
|
| 1021 | + public function log($level, $message, array $context = [ ]) |
|
| 1022 | 1022 | { |
| 1023 | - $level = isset(static::$logLevels[$level]) ? $level : self::INFO; |
|
| 1024 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$level]; |
|
| 1023 | + $level = isset(static::$logLevels[ $level ]) ? $level : self::INFO; |
|
| 1024 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $level ]; |
|
| 1025 | 1025 | unset($style); |
| 1026 | - if ( $logLevel > $this->level ) |
|
| 1026 | + if ($logLevel > $this->level) |
|
| 1027 | 1027 | { |
| 1028 | - return ; |
|
| 1028 | + return; |
|
| 1029 | 1029 | } |
| 1030 | - if ( is_callable($this->formatter) ) |
|
| 1030 | + if (is_callable($this->formatter)) |
|
| 1031 | 1031 | { |
| 1032 | - $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); |
|
| 1032 | + $message = $this->formatter->__invoke(static::$logLevels[ $level ][ 4 ], $message, $context); |
|
| 1033 | 1033 | } |
| 1034 | 1034 | else |
| 1035 | 1035 | { |
| 1036 | - $message = $this->formatMessage($level, $message, $context); |
|
| 1036 | + $message = $this->formatMessage($level, $message, $context); |
|
| 1037 | 1037 | } |
| 1038 | - $this->lastLogEntry = $message; |
|
| 1039 | - $this->write($this->colourize($message, $fore, $back) . PHP_EOL); |
|
| 1038 | + $this->lastLogEntry = $message; |
|
| 1039 | + $this->write($this->colourize($message, $fore, $back).PHP_EOL); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1046,8 +1046,8 @@ discard block |
||
| 1046 | 1046 | */ |
| 1047 | 1047 | public static function style(string $style, string $message) : string |
| 1048 | 1048 | { |
| 1049 | - $style = isset(static::$logLevels[$style]) ? $style : self::INFO; |
|
| 1050 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$style]; |
|
| 1049 | + $style = isset(static::$logLevels[ $style ]) ? $style : self::INFO; |
|
| 1050 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $style ]; |
|
| 1051 | 1051 | unset($logLevel, $style); |
| 1052 | 1052 | |
| 1053 | 1053 | return static::addColour($message, $fore, $back); |
@@ -1059,14 +1059,14 @@ discard block |
||
| 1059 | 1059 | * @param array $context |
| 1060 | 1060 | * @return string |
| 1061 | 1061 | */ |
| 1062 | - protected function formatMessage(string $level, string $message, array $context=[]) : string |
|
| 1062 | + protected function formatMessage(string $level, string $message, array $context = [ ]) : string |
|
| 1063 | 1063 | { |
| 1064 | 1064 | # Handle objects implementing __toString |
| 1065 | - $message = (string) $message; |
|
| 1066 | - $message .= empty($context) ? '' : PHP_EOL . json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
| 1067 | - $data = $this->addDate ? ['date' => date('Y-m-d H:i:s')] : []; |
|
| 1068 | - $data['level'] = strtoupper(str_pad(static::$logLevels[$level][4], 5, ' ', STR_PAD_RIGHT)); |
|
| 1069 | - $data['message'] = $message; |
|
| 1065 | + $message = (string)$message; |
|
| 1066 | + $message .= empty($context) ? '' : PHP_EOL.json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
|
| 1067 | + $data = $this->addDate ? [ 'date' => date('Y-m-d H:i:s') ] : [ ]; |
|
| 1068 | + $data[ 'level' ] = strtoupper(str_pad(static::$logLevels[ $level ][ 4 ], 5, ' ', STR_PAD_RIGHT)); |
|
| 1069 | + $data[ 'message' ] = $message; |
|
| 1070 | 1070 | |
| 1071 | 1071 | return implode($this->separator, $data); |
| 1072 | 1072 | } |
@@ -1079,12 +1079,12 @@ discard block |
||
| 1079 | 1079 | public function write(string $content) |
| 1080 | 1080 | { |
| 1081 | 1081 | $resource = $this->getResource(); |
| 1082 | - if ( $this->useLocking ) |
|
| 1082 | + if ($this->useLocking) |
|
| 1083 | 1083 | { |
| 1084 | 1084 | flock($resource, LOCK_EX); |
| 1085 | 1085 | } |
| 1086 | 1086 | gzwrite($resource, $content); |
| 1087 | - if ( $this->useLocking ) |
|
| 1087 | + if ($this->useLocking) |
|
| 1088 | 1088 | { |
| 1089 | 1089 | flock($resource, LOCK_UN); |
| 1090 | 1090 | } |
@@ -1096,14 +1096,14 @@ discard block |
||
| 1096 | 1096 | */ |
| 1097 | 1097 | protected function getResource() |
| 1098 | 1098 | { |
| 1099 | - if ( is_resource($this->resource) ) |
|
| 1099 | + if (is_resource($this->resource)) |
|
| 1100 | 1100 | { |
| 1101 | 1101 | return $this->resource; |
| 1102 | 1102 | } |
| 1103 | 1103 | $fileName = $this->resource; |
| 1104 | 1104 | $this->closeLocally = true; |
| 1105 | 1105 | $this->resource = $this->openResource(); |
| 1106 | - if ( ! is_resource($this->resource) ) |
|
| 1106 | + if ( ! is_resource($this->resource)) |
|
| 1107 | 1107 | { |
| 1108 | 1108 | throw new \Exception("The resource ({$fileName}) could not be opened"); |
| 1109 | 1109 | } |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | */ |
| 1125 | 1125 | protected function openResource() |
| 1126 | 1126 | { |
| 1127 | - if ( $this->gzipFile ) |
|
| 1127 | + if ($this->gzipFile) |
|
| 1128 | 1128 | { |
| 1129 | 1129 | return gzopen($this->resource, 'a'); |
| 1130 | 1130 | } |
@@ -347,8 +347,7 @@ discard block |
||
| 347 | 347 | $closure->__invoke($this); |
| 348 | 348 | } |
| 349 | 349 | $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); |
| 350 | - } |
|
| 351 | - catch ( \Exception $e ) |
|
| 350 | + } catch ( \Exception $e ) |
|
| 352 | 351 | { |
| 353 | 352 | $expectedCode = $testCase->getExceptionCode(); |
| 354 | 353 | $expectedClass = $testCase->getExceptionType(); |
@@ -1030,8 +1029,7 @@ discard block |
||
| 1030 | 1029 | if ( is_callable($this->formatter) ) |
| 1031 | 1030 | { |
| 1032 | 1031 | $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); |
| 1033 | - } |
|
| 1034 | - else |
|
| 1032 | + } else |
|
| 1035 | 1033 | { |
| 1036 | 1034 | $message = $this->formatMessage($level, $message, $context); |
| 1037 | 1035 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 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 | |
@@ -29,5 +29,5 @@ |
||
| 29 | 29 | * |
| 30 | 30 | * @var string |
| 31 | 31 | */ |
| 32 | - protected $exceptionClass = ValidationFailedException::class; |
|
| 32 | + protected $exceptionClass = ValidationFailedException::class; |
|
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | * @param string $level |
| 32 | 32 | * @return Assert |
| 33 | 33 | */ |
| 34 | -function Assert($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 34 | +function Assert($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
| 35 | 35 | { |
| 36 | 36 | $assert = new Assert($value); |
| 37 | - if ( $fieldName ) |
|
| 37 | + if ($fieldName) |
|
| 38 | 38 | { |
| 39 | 39 | $assert->fieldName($fieldName); |
| 40 | 40 | } |
| 41 | - if ( $code ) |
|
| 41 | + if ($code) |
|
| 42 | 42 | { |
| 43 | 43 | $assert->code($code); |
| 44 | 44 | } |
| 45 | - if ( $error ) |
|
| 45 | + if ($error) |
|
| 46 | 46 | { |
| 47 | 47 | $assert->error($error); |
| 48 | 48 | } |
| 49 | - if ( $level ) |
|
| 49 | + if ($level) |
|
| 50 | 50 | { |
| 51 | 51 | $assert->level($level); |
| 52 | 52 | } |
@@ -64,22 +64,22 @@ discard block |
||
| 64 | 64 | * @param string $level |
| 65 | 65 | * @return Assert |
| 66 | 66 | */ |
| 67 | -function Validate($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 67 | +function Validate($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
| 68 | 68 | { |
| 69 | 69 | $assert = new Assert($value); |
| 70 | - if ( $fieldName ) |
|
| 70 | + if ($fieldName) |
|
| 71 | 71 | { |
| 72 | 72 | $assert->fieldName($fieldName); |
| 73 | 73 | } |
| 74 | - if ( $code ) |
|
| 74 | + if ($code) |
|
| 75 | 75 | { |
| 76 | 76 | $assert->code($code); |
| 77 | 77 | } |
| 78 | - if ( $error ) |
|
| 78 | + if ($error) |
|
| 79 | 79 | { |
| 80 | 80 | $assert->error($error); |
| 81 | 81 | } |
| 82 | - if ( $level ) |
|
| 82 | + if ($level) |
|
| 83 | 83 | { |
| 84 | 84 | $assert->level($level); |
| 85 | 85 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $level |
| 42 | 42 | * @param string $propertyPath |
| 43 | 43 | */ |
| 44 | - public function __construct(string $message, int $code, string $fieldName='', $value='', array $constraints=[], string $level='critical', string $propertyPath='') |
|
| 44 | + public function __construct(string $message, int $code, string $fieldName = '', $value = '', array $constraints = [ ], string $level = 'critical', string $propertyPath = '') |
|
| 45 | 45 | { |
| 46 | 46 | parent::__construct($message, $code); |
| 47 | 47 | $this->fieldName = $fieldName; |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | $this->constraints = $constraints; |
| 50 | 50 | $this->level = $level; |
| 51 | 51 | $this->propertyPath = $propertyPath; |
| 52 | - foreach ( $this->getTrace() as $point ) |
|
| 52 | + foreach ($this->getTrace() as $point) |
|
| 53 | 53 | { |
| 54 | - $class = $point['class'] ??0?: ''; |
|
| 55 | - if ( $class !== Assert::class ) |
|
| 54 | + $class = $point[ 'class' ] ??0 ?: ''; |
|
| 55 | + if ($class !== Assert::class) |
|
| 56 | 56 | { |
| 57 | 57 | $this->location = (object)$point; |
| 58 | 58 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function getPropertyPathAndCallingLocation() : string |
| 124 | 124 | { |
| 125 | - return $this->getPropertyPath() . ' in ' . $this->getCallingFileAndLine(); |
|
| 125 | + return $this->getPropertyPath().' in '.$this->getCallingFileAndLine(); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function getCallingFileAndLine() : string |
| 135 | 135 | { |
| 136 | - foreach ( $this->getTrace() as $trace ) |
|
| 136 | + foreach ($this->getTrace() as $trace) |
|
| 137 | 137 | { |
| 138 | 138 | $trace = (object)$trace; |
| 139 | - if ( empty($trace->file) ) |
|
| 139 | + if (empty($trace->file)) |
|
| 140 | 140 | { |
| 141 | 141 | continue; |
| 142 | 142 | } |
| 143 | 143 | $file = static::beforeLast('.php', static::afterLast('/', $trace->file)); |
| 144 | - if ( in_array($file, ['AssertionChain', 'Assertion']) ) |
|
| 144 | + if (in_array($file, [ 'AssertionChain', 'Assertion' ])) |
|
| 145 | 145 | { |
| 146 | 146 | continue; |
| 147 | 147 | } |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | * @param bool $returnOriginal |
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | - public static function afterLast(string $needle, string $haystack, bool $returnOriginal=false) : string |
|
| 171 | + public static function afterLast(string $needle, string $haystack, bool $returnOriginal = false) : string |
|
| 172 | 172 | { |
| 173 | - if ( static::strrevpos($haystack, $needle) !== -1 ) |
|
| 173 | + if (static::strrevpos($haystack, $needle) !== -1) |
|
| 174 | 174 | { |
| 175 | 175 | return mb_substr($haystack, static::strrevpos($haystack, $needle) + mb_strlen($needle)); |
| 176 | 176 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public static function beforeLast(string $needle, string $haystack) : string |
| 199 | 199 | { |
| 200 | - $position = static::strrevpos($haystack, $needle); |
|
| 200 | + $position = static::strrevpos($haystack, $needle); |
|
| 201 | 201 | |
| 202 | 202 | return $position === -1 ? '' : mb_substr($haystack, 0, static::strrevpos($haystack, $needle)); |
| 203 | 203 | } |