From d6a21f8f66db992d7bfae031da3ad4c7aa9c7a13 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Thu, 25 Jan 2018 12:55:23 +0000 Subject: [PATCH] `\Assert\Assertion::generateMessage()` will now receive the default message for an assertion if one is not supplied (Thanks to [Romans Malinovskis](https://github.com/beberlei/assert/issues/225)) --- .travis.yml | 4 +- CHANGELOG.md | 15 ++-- lib/Assert/Assertion.php | 152 +++++++++++++++++++-------------------- 3 files changed, 89 insertions(+), 82 deletions(-) diff --git a/.travis.yml b/.travis.yml index b51b49b5..aacf4546 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ matrix: env: - LINT=true - php: 7.2 + env: + - LINT=true - php: nightly - php: hhvm-3.9 sudo: required @@ -45,7 +47,7 @@ script: composer assert:cs-lint; ./bin/travis/lint-docs; composer require --dev phpstan/phpstan; - vendor/bin/phpstan analyse --no-progress --ansi -l 5 lib; + vendor/bin/phpstan analyse --no-progress --ansi -l 7 lib; fi - if [[ "$COVERAGE" == "true" ]]; then xdebug-enable; diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df9d291..c6d71baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +## x.y.z - ccyy-mm-dd + +### Fixes +- `\Assert\Assertion::generateMessage()` will now receive the default message for an assertion if one is not supplied (Thanks to [Romans Malinovskis](https://github.com/beberlei/assert/issues/225)) + ## 2.8.1 - 2017-11-30 ### Fixes @@ -20,27 +25,27 @@ All notable changes to this project will be documented in this file. ## 2.7.10 - 2017-11-13 ### Added assertions -- `Assertion::base64()` (Thank to [Pablo Kowalczyk](https://github.com/beberlei/assert/pull/232)) +- `Assertion::base64()` (Thanks to [Pablo Kowalczyk](https://github.com/beberlei/assert/pull/232)) ## 2.7.9 - 2017-11-13 ### Fixes -- `Assertion::integerish()` now correctly asserts integers with leading zeros in strings (Thank to [Albert Casademont](https://github.com/beberlei/assert/pull/227#issuecomment-343961009)) +- `Assertion::integerish()` now correctly asserts integers with leading zeros in strings (Thanks to [Albert Casademont](https://github.com/beberlei/assert/pull/227#issuecomment-343961009)) ## 2.7.8 - 2017-10-20 ### Fixes -- `Assertion::integerish()` now throws exception as expected (Thank to [Thomas Flack](https://github.com/beberlei/assert/issues/235)) +- `Assertion::integerish()` now throws exception as expected (Thanks to [Thomas Flack](https://github.com/beberlei/assert/issues/235)) ## 2.7.7 - 2017-10-18 ### Fixes -- Basic Auth usernames and passwords can contain '.' (Thank to [Fede Isas](https://github.com/beberlei/assert/issues/234)) +- Basic Auth usernames and passwords can contain '.' (Thanks to [Fede Isas](https://github.com/beberlei/assert/issues/234)) ## 2.7.6 - 2017-05-04 ### Fixes -- Fixed stringification of booleans (Thank to [Philipp Rieber](https://github.com/beberlei/assert/issues/226)) +- Fixed stringification of booleans (Thanks to [Philipp Rieber](https://github.com/beberlei/assert/issues/226)) ## 2.7.5 - 2017-04-29 ### Added assertions diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 28a9bf4a..78cf2c11 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -304,7 +304,7 @@ public static function eq($value, $value2, $message = null, $propertyPath = null { if ($value != $value2) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" does not equal expected value "%s".', + static::generateMessage($message ?: 'Value "%s" does not equal expected value "%s".'), static::stringify($value), static::stringify($value2) ); @@ -331,7 +331,7 @@ public static function same($value, $value2, $message = null, $propertyPath = nu { if ($value !== $value2) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not the same as expected value "%s".', + static::generateMessage($message ?: 'Value "%s" is not the same as expected value "%s".'), static::stringify($value), static::stringify($value2) ); @@ -358,7 +358,7 @@ public static function notEq($value1, $value2, $message = null, $propertyPath = { if ($value1 == $value2) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is equal to expected value "%s".', + static::generateMessage($message ?: 'Value "%s" is equal to expected value "%s".'), static::stringify($value1), static::stringify($value2) ); @@ -384,7 +384,7 @@ public static function notSame($value1, $value2, $message = null, $propertyPath { if ($value1 === $value2) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is the same as expected value "%s".', + static::generateMessage($message ?: 'Value "%s" is the same as expected value "%s".'), static::stringify($value1), static::stringify($value2) ); @@ -410,7 +410,7 @@ public static function notInArray($value, array $choices, $message = null, $prop { if (true === \in_array($value, $choices)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is in given "%s".', + static::generateMessage($message ?: 'Value "%s" is in given "%s".'), static::stringify($value), static::stringify($choices) ); @@ -435,7 +435,7 @@ public static function integer($value, $message = null, $propertyPath = null) { if (!\is_int($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an integer.', + static::generateMessage($message ?: 'Value "%s" is not an integer.'), static::stringify($value) ); @@ -460,7 +460,7 @@ public static function float($value, $message = null, $propertyPath = null) { if (!\is_float($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a float.', + static::generateMessage($message ?: 'Value "%s" is not a float.'), static::stringify($value) ); @@ -485,7 +485,7 @@ public static function digit($value, $message = null, $propertyPath = null) { if (!\ctype_digit((string) $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a digit.', + static::generateMessage($message ?: 'Value "%s" is not a digit.'), static::stringify($value) ); @@ -523,7 +523,7 @@ public static function integerish($value, $message = null, $propertyPath = null) ) ) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an integer or a number castable to integer.', + static::generateMessage($message ?: 'Value "%s" is not an integer or a number castable to integer.'), static::stringify($value) ); @@ -548,7 +548,7 @@ public static function boolean($value, $message = null, $propertyPath = null) { if (!\is_bool($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a boolean.', + static::generateMessage($message ?: 'Value "%s" is not a boolean.'), static::stringify($value) ); @@ -573,7 +573,7 @@ public static function scalar($value, $message = null, $propertyPath = null) { if (!\is_scalar($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a scalar.', + static::generateMessage($message ?: 'Value "%s" is not a scalar.'), static::stringify($value) ); @@ -598,7 +598,7 @@ public static function notEmpty($value, $message = null, $propertyPath = null) { if (empty($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is empty, but non empty value was expected.', + static::generateMessage($message ?: 'Value "%s" is empty, but non empty value was expected.'), static::stringify($value) ); @@ -623,7 +623,7 @@ public static function noContent($value, $message = null, $propertyPath = null) { if (!empty($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not empty, but empty value was expected.', + static::generateMessage($message ?: 'Value "%s" is not empty, but empty value was expected.'), static::stringify($value) ); @@ -648,7 +648,7 @@ public static function null($value, $message = null, $propertyPath = null) { if (null !== $value) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not null, but null value was expected.', + static::generateMessage($message ?: 'Value "%s" is not null, but null value was expected.'), static::stringify($value) ); @@ -673,7 +673,7 @@ public static function notNull($value, $message = null, $propertyPath = null) { if (null === $value) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is null, but non null value was expected.', + static::generateMessage($message ?: 'Value "%s" is null, but non null value was expected.'), static::stringify($value) ); @@ -698,7 +698,7 @@ public static function string($value, $message = null, $propertyPath = null) { if (!\is_string($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" expected to be string, type %s given.', + static::generateMessage($message ?: 'Value "%s" expected to be string, type %s given.'), static::stringify($value), \gettype($value) ); @@ -727,7 +727,7 @@ public static function regex($value, $pattern, $message = null, $propertyPath = if (!\preg_match($pattern, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" does not match expression.', + static::generateMessage($message ?: 'Value "%s" does not match expression.'), static::stringify($value) ); @@ -756,7 +756,7 @@ public static function length($value, $length, $message = null, $propertyPath = if (\mb_strlen($value, $encoding) !== $length) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" has to be %d exactly characters long, but length is %d.', + static::generateMessage($message ?: 'Value "%s" has to be %d exactly characters long, but length is %d.'), static::stringify($value), $length, \mb_strlen($value, $encoding) @@ -788,7 +788,7 @@ public static function minLength($value, $minLength, $message = null, $propertyP if (\mb_strlen($value, $encoding) < $minLength) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is too short, it should have at least %d characters, but only has %d characters.', + static::generateMessage($message ?: 'Value "%s" is too short, it should have at least %d characters, but only has %d characters.'), static::stringify($value), $minLength, \mb_strlen($value, $encoding) @@ -820,7 +820,7 @@ public static function maxLength($value, $maxLength, $message = null, $propertyP if (\mb_strlen($value, $encoding) > $maxLength) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', + static::generateMessage($message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.'), static::stringify($value), $maxLength, \mb_strlen($value, $encoding) @@ -875,7 +875,7 @@ public static function startsWith($string, $needle, $message = null, $propertyPa if (0 !== \mb_strpos($string, $needle, null, $encoding)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" does not start with "%s".', + static::generateMessage($message ?: 'Value "%s" does not start with "%s".'), static::stringify($string), static::stringify($needle) ); @@ -908,7 +908,7 @@ public static function endsWith($string, $needle, $message = null, $propertyPath if (\mb_strripos($string, $needle, null, $encoding) !== $stringPosition) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" does not end with "%s".', + static::generateMessage($message ?: 'Value "%s" does not end with "%s".'), static::stringify($string), static::stringify($needle) ); @@ -939,7 +939,7 @@ public static function contains($string, $needle, $message = null, $propertyPath if (false === \mb_strpos($string, $needle, null, $encoding)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" does not contain "%s".', + static::generateMessage($message ?: 'Value "%s" does not contain "%s".'), static::stringify($string), static::stringify($needle) ); @@ -967,7 +967,7 @@ public static function choice($value, array $choices, $message = null, $property { if (!\in_array($value, $choices, true)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an element of the valid values: %s', + static::generateMessage($message ?: 'Value "%s" is not an element of the valid values: %s'), static::stringify($value), \implode(', ', \array_map(array(\get_called_class(), 'stringify'), $choices)) ); @@ -1012,7 +1012,7 @@ public static function numeric($value, $message = null, $propertyPath = null) { if (!\is_numeric($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not numeric.', + static::generateMessage($message ?: 'Value "%s" is not numeric.'), static::stringify($value) ); @@ -1037,7 +1037,7 @@ public static function isResource($value, $message = null, $propertyPath = null) { if (!\is_resource($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a resource.', + static::generateMessage($message ?: 'Value "%s" is not a resource.'), static::stringify($value) ); @@ -1062,7 +1062,7 @@ public static function isArray($value, $message = null, $propertyPath = null) { if (!\is_array($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an array.', + static::generateMessage($message ?: 'Value "%s" is not an array.'), static::stringify($value) ); @@ -1087,7 +1087,7 @@ public static function isTraversable($value, $message = null, $propertyPath = nu { if (!\is_array($value) && !$value instanceof \Traversable) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an array and does not implement Traversable.', + static::generateMessage($message ?: 'Value "%s" is not an array and does not implement Traversable.'), static::stringify($value) ); @@ -1112,7 +1112,7 @@ public static function isArrayAccessible($value, $message = null, $propertyPath { if (!\is_array($value) && !$value instanceof \ArrayAccess) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not an array and does not implement ArrayAccess.', + static::generateMessage($message ?: 'Value "%s" is not an array and does not implement ArrayAccess.'), static::stringify($value) ); @@ -1140,7 +1140,7 @@ public static function keyExists($value, $key, $message = null, $propertyPath = if (!\array_key_exists($key, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Array does not contain an element with key "%s"', + static::generateMessage($message ?: 'Array does not contain an element with key "%s"'), static::stringify($key) ); @@ -1168,7 +1168,7 @@ public static function keyNotExists($value, $key, $message = null, $propertyPath if (\array_key_exists($key, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Array contains an element with key "%s"', + static::generateMessage($message ?: 'Array contains an element with key "%s"'), static::stringify($key) ); @@ -1196,7 +1196,7 @@ public static function keyIsset($value, $key, $message = null, $propertyPath = n if (!isset($value[$key])) { $message = \sprintf( - static::generateMessage($message) ?: 'The element with key "%s" was not found', + static::generateMessage($message ?: 'The element with key "%s" was not found'), static::stringify($key) ); @@ -1241,7 +1241,7 @@ public static function notBlank($value, $message = null, $propertyPath = null) { if (false === $value || (empty($value) && '0' != $value) || (\is_string($value) && '' === \trim($value))) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is blank, but was expected to contain a value.', + static::generateMessage($message ?: 'Value "%s" is blank, but was expected to contain a value.'), static::stringify($value) ); @@ -1267,7 +1267,7 @@ public static function isInstanceOf($value, $className, $message = null, $proper { if (!($value instanceof $className)) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" was expected to be instanceof of "%s" but is not.', + static::generateMessage($message ?: 'Class "%s" was expected to be instanceof of "%s" but is not.'), static::stringify($value), $className ); @@ -1294,7 +1294,7 @@ public static function notIsInstanceOf($value, $className, $message = null, $pro { if ($value instanceof $className) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" was not expected to be instanceof of "%s".', + static::generateMessage($message ?: 'Class "%s" was not expected to be instanceof of "%s".'), static::stringify($value), $className ); @@ -1321,7 +1321,7 @@ public static function subclassOf($value, $className, $message = null, $property { if (!\is_subclass_of($value, $className)) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" was expected to be subclass of "%s".', + static::generateMessage($message ?: 'Class "%s" was expected to be subclass of "%s".'), static::stringify($value), $className ); @@ -1351,7 +1351,7 @@ public static function range($value, $minValue, $maxValue, $message = null, $pro if ($value < $minValue || $value > $maxValue) { $message = \sprintf( - static::generateMessage($message) ?: 'Number "%s" was expected to be at least "%d" and at most "%d".', + static::generateMessage($message ?: 'Number "%s" was expected to be at least "%d" and at most "%d".'), static::stringify($value), static::stringify($minValue), static::stringify($maxValue) @@ -1381,7 +1381,7 @@ public static function min($value, $minValue, $message = null, $propertyPath = n if ($value < $minValue) { $message = \sprintf( - static::generateMessage($message) ?: 'Number "%s" was expected to be at least "%s".', + static::generateMessage($message ?: 'Number "%s" was expected to be at least "%s".'), static::stringify($value), static::stringify($minValue) ); @@ -1410,7 +1410,7 @@ public static function max($value, $maxValue, $message = null, $propertyPath = n if ($value > $maxValue) { $message = \sprintf( - static::generateMessage($message) ?: 'Number "%s" was expected to be at most "%s".', + static::generateMessage($message ?: 'Number "%s" was expected to be at most "%s".'), static::stringify($value), static::stringify($maxValue) ); @@ -1439,7 +1439,7 @@ public static function file($value, $message = null, $propertyPath = null) if (!\is_file($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'File "%s" was expected to exist.', + static::generateMessage($message ?: 'File "%s" was expected to exist.'), static::stringify($value) ); @@ -1466,7 +1466,7 @@ public static function directory($value, $message = null, $propertyPath = null) if (!\is_dir($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Path "%s" was expected to be a directory.', + static::generateMessage($message ?: 'Path "%s" was expected to be a directory.'), static::stringify($value) ); @@ -1493,7 +1493,7 @@ public static function readable($value, $message = null, $propertyPath = null) if (!\is_readable($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Path "%s" was expected to be readable.', + static::generateMessage($message ?: 'Path "%s" was expected to be readable.'), static::stringify($value) ); @@ -1520,7 +1520,7 @@ public static function writeable($value, $message = null, $propertyPath = null) if (!\is_writable($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Path "%s" was expected to be writeable.', + static::generateMessage($message ?: 'Path "%s" was expected to be writeable.'), static::stringify($value) ); @@ -1547,7 +1547,7 @@ public static function email($value, $message = null, $propertyPath = null) if (!\filter_var($value, FILTER_VALIDATE_EMAIL)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" was expected to be a valid e-mail address.', + static::generateMessage($message ?: 'Value "%s" was expected to be a valid e-mail address.'), static::stringify($value) ); @@ -1558,7 +1558,7 @@ public static function email($value, $message = null, $propertyPath = null) // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 if (\version_compare(PHP_VERSION, '5.3.3', '<') && false === \strpos($host, '.')) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" was expected to be a valid e-mail address.', + static::generateMessage($message ?: 'Value "%s" was expected to be a valid e-mail address.'), static::stringify($value) ); @@ -1611,7 +1611,7 @@ public static function url($value, $message = null, $propertyPath = null) if (!\preg_match($pattern, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" was expected to be a valid URL starting with http or https', + static::generateMessage($message ?: 'Value "%s" was expected to be a valid URL starting with http or https'), static::stringify($value) ); @@ -1638,7 +1638,7 @@ public static function alnum($value, $message = null, $propertyPath = null) static::regex($value, '(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); } catch (AssertionFailedException $e) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', + static::generateMessage($message ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.'), static::stringify($value) ); @@ -1663,7 +1663,7 @@ public static function true($value, $message = null, $propertyPath = null) { if (true !== $value) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not TRUE.', + static::generateMessage($message ?: 'Value "%s" is not TRUE.'), static::stringify($value) ); @@ -1688,7 +1688,7 @@ public static function false($value, $message = null, $propertyPath = null) { if (false !== $value) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not FALSE.', + static::generateMessage($message ?: 'Value "%s" is not FALSE.'), static::stringify($value) ); @@ -1713,7 +1713,7 @@ public static function classExists($value, $message = null, $propertyPath = null { if (!\class_exists($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" does not exist.', + static::generateMessage($message ?: 'Class "%s" does not exist.'), static::stringify($value) ); @@ -1738,7 +1738,7 @@ public static function interfaceExists($value, $message = null, $propertyPath = { if (!\interface_exists($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Interface "%s" does not exist.', + static::generateMessage($message ?: 'Interface "%s" does not exist.'), static::stringify($value) ); @@ -1765,7 +1765,7 @@ public static function implementsInterface($class, $interfaceName, $message = nu $reflection = new \ReflectionClass($class); if (!$reflection->implementsInterface($interfaceName)) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" does not implement interface "%s".', + static::generateMessage($message ?: 'Class "%s" does not implement interface "%s".'), static::stringify($class), static::stringify($interfaceName) ); @@ -1797,7 +1797,7 @@ public static function isJsonString($value, $message = null, $propertyPath = nul { if (null === \json_decode($value) && JSON_ERROR_NONE !== \json_last_error()) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a valid JSON string.', + static::generateMessage($message ?: 'Value "%s" is not a valid JSON string.'), static::stringify($value) ); @@ -1830,7 +1830,7 @@ public static function uuid($value, $message = null, $propertyPath = null) 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}$/', $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a valid UUID.', + static::generateMessage($message ?: 'Value "%s" is not a valid UUID.'), static::stringify($value) ); @@ -1857,7 +1857,7 @@ public static function e164($value, $message = null, $propertyPath = null) { if (!\preg_match('/^\+?[1-9]\d{1,14}$/', $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" is not a valid E164.', + static::generateMessage($message ?: 'Value "%s" is not a valid E164.'), static::stringify($value) ); @@ -1883,7 +1883,7 @@ public static function count($countable, $count, $message = null, $propertyPath { if ($count !== \count($countable)) { $message = \sprintf( - static::generateMessage($message) ?: 'List does not contain exactly "%d" elements.', + static::generateMessage($message ?: 'List does not contain exactly "%d" elements.'), static::stringify($count) ); @@ -1979,7 +1979,7 @@ public static function methodExists($value, $object, $message = null, $propertyP if (!\method_exists($object, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Expected "%s" does not exist in provided object.', + static::generateMessage($message ?: 'Expected "%s" does not exist in provided object.'), static::stringify($value) ); @@ -2002,7 +2002,7 @@ public static function isObject($value, $message = null, $propertyPath = null) { if (!\is_object($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not a valid object.', + static::generateMessage($message ?: 'Provided "%s" is not a valid object.'), static::stringify($value) ); @@ -2026,7 +2026,7 @@ public static function lessThan($value, $limit, $message = null, $propertyPath = { if ($value >= $limit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not less than "%s".', + static::generateMessage($message ?: 'Provided "%s" is not less than "%s".'), static::stringify($value), static::stringify($limit) ); @@ -2051,7 +2051,7 @@ public static function lessOrEqualThan($value, $limit, $message = null, $propert { if ($value > $limit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not less or equal than "%s".', + static::generateMessage($message ?: 'Provided "%s" is not less or equal than "%s".'), static::stringify($value), static::stringify($limit) ); @@ -2076,7 +2076,7 @@ public static function greaterThan($value, $limit, $message = null, $propertyPat { if ($value <= $limit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not greater than "%s".', + static::generateMessage($message ?: 'Provided "%s" is not greater than "%s".'), static::stringify($value), static::stringify($limit) ); @@ -2101,7 +2101,7 @@ public static function greaterOrEqualThan($value, $limit, $message = null, $prop { if ($value < $limit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not greater or equal than "%s".', + static::generateMessage($message ?: 'Provided "%s" is not greater or equal than "%s".'), static::stringify($value), static::stringify($limit) ); @@ -2127,7 +2127,7 @@ public static function between($value, $lowerLimit, $upperLimit, $message = null { if ($lowerLimit > $value || $value > $upperLimit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is neither greater than or equal to "%s" nor less than or equal to "%s".', + static::generateMessage($message ?: 'Provided "%s" is neither greater than or equal to "%s" nor less than or equal to "%s".'), static::stringify($value), static::stringify($lowerLimit), static::stringify($upperLimit) @@ -2154,7 +2154,7 @@ public static function betweenExclusive($value, $lowerLimit, $upperLimit, $messa { if ($lowerLimit >= $value || $value >= $upperLimit) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is neither greater than "%s" nor less than "%s".', + static::generateMessage($message ?: 'Provided "%s" is neither greater than "%s" nor less than "%s".'), static::stringify($value), static::stringify($lowerLimit), static::stringify($upperLimit) @@ -2181,7 +2181,7 @@ public static function extensionLoaded($value, $message = null, $propertyPath = { if (!\extension_loaded($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Extension "%s" is required.', + static::generateMessage($message ?: 'Extension "%s" is required.'), static::stringify($value) ); @@ -2213,7 +2213,7 @@ public static function date($value, $format, $message = null, $propertyPath = nu if (false === $dateTime || $value !== $dateTime->format($format)) { $message = \sprintf( - static::generateMessage($message) ?: 'Date "%s" is invalid or does not match format "%s".', + static::generateMessage($message ?: 'Date "%s" is invalid or does not match format "%s".'), static::stringify($value), static::stringify($format) ); @@ -2262,7 +2262,7 @@ public static function propertyExists($value, $property, $message = null, $prope if (!\property_exists($value, $property)) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" does not have property "%s".', + static::generateMessage($message ?: 'Class "%s" does not have property "%s".'), static::stringify($value), static::stringify($property) ); @@ -2299,7 +2299,7 @@ public static function propertiesExist($value, array $properties, $message = nul if ($invalidProperties) { $message = \sprintf( - static::generateMessage($message) ?: 'Class "%s" does not have these properties: %s.', + static::generateMessage($message ?: 'Class "%s" does not have these properties: %s.'), static::stringify($value), static::stringify(\implode(', ', $invalidProperties)) ); @@ -2329,7 +2329,7 @@ public static function version($version1, $operator, $version2, $message = null, if (true !== \version_compare($version1, $version2, $operator)) { $message = \sprintf( - static::generateMessage($message) ?: 'Version "%s" is not "%s" version "%s".', + static::generateMessage($message ?: 'Version "%s" is not "%s" version "%s".'), static::stringify($version1), static::stringify($operator), static::stringify($version2) @@ -2393,7 +2393,7 @@ public static function isCallable($value, $message = null, $propertyPath = null) { if (!\is_callable($value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is not a callable.', + static::generateMessage($message ?: 'Provided "%s" is not a callable.'), static::stringify($value) ); @@ -2421,7 +2421,7 @@ public static function satisfy($value, $callback, $message = null, $propertyPath if (false === \call_user_func($callback, $value)) { $message = \sprintf( - static::generateMessage($message) ?: 'Provided "%s" is invalid according to custom rule.', + static::generateMessage($message ?: 'Provided "%s" is invalid according to custom rule.'), static::stringify($value) ); @@ -2449,7 +2449,7 @@ public static function ip($value, $flag = null, $message = null, $propertyPath = static::string($value, $message, $propertyPath); if (!\filter_var($value, FILTER_VALIDATE_IP, $flag)) { $message = \sprintf( - static::generateMessage($message) ?: 'Value "%s" was expected to be a valid IP address.', + static::generateMessage($message ?: 'Value "%s" was expected to be a valid IP address.'), static::stringify($value) ); throw static::createException($value, $message, static::INVALID_IP, $propertyPath); @@ -2473,7 +2473,7 @@ public static function ip($value, $flag = null, $message = null, $propertyPath = */ public static function ipv4($value, $flag = null, $message = null, $propertyPath = null) { - static::ip($value, $flag | FILTER_FLAG_IPV4, static::generateMessage($message) ?: 'Value "%s" was expected to be a valid IPv4 address.', $propertyPath); + static::ip($value, $flag | FILTER_FLAG_IPV4, static::generateMessage($message ?: 'Value "%s" was expected to be a valid IPv4 address.'), $propertyPath); return true; } @@ -2493,7 +2493,7 @@ public static function ipv4($value, $flag = null, $message = null, $propertyPath */ public static function ipv6($value, $flag = null, $message = null, $propertyPath = null) { - static::ip($value, $flag | FILTER_FLAG_IPV6, static::generateMessage($message) ?: 'Value "%s" was expected to be a valid IPv6 address.', $propertyPath); + static::ip($value, $flag | FILTER_FLAG_IPV6, static::generateMessage($message ?: 'Value "%s" was expected to be a valid IPv6 address.'), $propertyPath); return true; } @@ -2546,7 +2546,7 @@ protected static function stringify($value) public static function defined($constant, $message = null, $propertyPath = null) { if (!\defined($constant)) { - $message = \sprintf(static::generateMessage($message) ?: 'Value "%s" expected to be a defined constant.', $constant); + $message = \sprintf(static::generateMessage($message ?: 'Value "%s" expected to be a defined constant.'), $constant); throw static::createException($constant, $message, static::INVALID_CONSTANT, $propertyPath); } @@ -2568,7 +2568,7 @@ public static function defined($constant, $message = null, $propertyPath = null) public static function base64($value, $message = null, $propertyPath = null) { if (false === \base64_decode($value, true)) { - $message = \sprintf(static::generateMessage($message) ?: 'Value "%s" is not a valid base64 string.', $value); + $message = \sprintf(static::generateMessage($message ?: 'Value "%s" is not a valid base64 string.'), $value); throw static::createException($value, $message, static::INVALID_BASE64, $propertyPath); }