From b899c6ed79b10a296c27e9a5a9e21edecd52d87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Thu, 27 Dec 2018 15:39:56 +0100 Subject: [PATCH] Add a empty alias for noContent --- README.md | 1 + lib/Assert/Assertion.php | 24 +++++++++++++++++++++--- lib/Assert/AssertionChain.php | 3 ++- lib/Assert/LazyAssertion.php | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2b934c67..cb4b4ee0 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ Assertion::digit(mixed $value); Assertion::directory(string $value); Assertion::e164(string $value); Assertion::email(mixed $value); +Assertion::empty(mixed $value); Assertion::endsWith(mixed $string, string $needle); Assertion::eq(mixed $value, mixed $value2); Assertion::eqArraySubset(mixed $value, mixed $value2); diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 6f5b3c2d..86983f5e 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -47,6 +47,7 @@ * @method static bool allDirectory(string $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists for all values. * @method static bool allE164(string $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number for all values. * @method static bool allEmail(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL) for all values. + * @method static bool allEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values. * @method static bool allEndsWith(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars for all values. * @method static bool allEq(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==) for all values. * @method static bool allEqArraySubset(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset for all values. @@ -87,7 +88,7 @@ * @method static bool allMin(mixed $value, mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit for all values. * @method static bool allMinCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements for all values. * @method static bool allMinLength(mixed $value, int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long for all values. - * @method static bool allNoContent(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values. + * @method static bool allNoContent(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of Assertion::empty() for all values. * @method static bool allNotBlank(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank for all values. * @method static bool allNotContains(mixed $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars for all values. * @method static bool allNotEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty for all values. @@ -135,6 +136,7 @@ * @method static bool nullOrDirectory(string|null $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists or that the value is null. * @method static bool nullOrE164(string|null $value, string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number or that the value is null. * @method static bool nullOrEmail(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL) or that the value is null. + * @method static bool nullOrEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty or that the value is null. * @method static bool nullOrEndsWith(mixed|null $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars or that the value is null. * @method static bool nullOrEq(mixed|null $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==) or that the value is null. * @method static bool nullOrEqArraySubset(mixed|null $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset or that the value is null. @@ -175,7 +177,7 @@ * @method static bool nullOrMin(mixed|null $value, mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit or that the value is null. * @method static bool nullOrMinCount(array|Countable|ResourceBundle|SimpleXMLElement|null $countable, int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements or that the value is null. * @method static bool nullOrMinLength(mixed|null $value, int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long or that the value is null. - * @method static bool nullOrNoContent(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty or that the value is null. + * @method static bool nullOrNoContent(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of Assertion::empty() or that the value is null. * @method static bool nullOrNotBlank(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank or that the value is null. * @method static bool nullOrNotContains(mixed|null $string, string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars or that the value is null. * @method static bool nullOrNotEmpty(mixed|null $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty or that the value is null. @@ -649,7 +651,7 @@ public static function notEmpty($value, $message = null, string $propertyPath = * * @throws AssertionFailedException */ - public static function noContent($value, $message = null, string $propertyPath = null): bool + public static function empty($value, $message = null, string $propertyPath = null): bool { if (!empty($value)) { $message = \sprintf( @@ -663,6 +665,22 @@ public static function noContent($value, $message = null, string $propertyPath = return true; } + /** + * Assert that value is empty. + * + * This is an alias of {@see empty()}. + * + * @param mixed $value + * @param string|callable|null $message + * @param string|null $propertyPath + * + * @return bool + */ + public static function noContent($value, $message = null, string $propertyPath = null): bool + { + return static::empty($value, $message, $propertyPath); + } + /** * Assert that value is null. * diff --git a/lib/Assert/AssertionChain.php b/lib/Assert/AssertionChain.php index dbb6e839..7c98277a 100644 --- a/lib/Assert/AssertionChain.php +++ b/lib/Assert/AssertionChain.php @@ -39,6 +39,7 @@ * @method AssertionChain directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. * @method AssertionChain e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. * @method AssertionChain email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). + * @method AssertionChain empty(string|callable $message = null, string $propertyPath = null) Assert that value is empty. * @method AssertionChain endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. * @method AssertionChain eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). * @method AssertionChain eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. @@ -79,7 +80,7 @@ * @method AssertionChain min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. * @method AssertionChain minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. * @method AssertionChain minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. - * @method AssertionChain noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. + * @method AssertionChain noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of Assertion::empty(). * @method AssertionChain notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. * @method AssertionChain notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. * @method AssertionChain notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty. diff --git a/lib/Assert/LazyAssertion.php b/lib/Assert/LazyAssertion.php index 9301c6b4..6fc68ac9 100644 --- a/lib/Assert/LazyAssertion.php +++ b/lib/Assert/LazyAssertion.php @@ -38,6 +38,7 @@ * @method $this directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists. * @method $this e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number. * @method $this email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL). + * @method $this empty(string|callable $message = null, string $propertyPath = null) Assert that value is empty. * @method $this endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars. * @method $this eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==). * @method $this eqArraySubset(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that the array contains the subset. @@ -78,7 +79,7 @@ * @method $this min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit. * @method $this minCount(int $count, string|callable $message = null, string $propertyPath = null) Assert that the countable have at least $count elements. * @method $this minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long. - * @method $this noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. + * @method $this noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of LazyAssertion::empty(). * @method $this notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank. * @method $this notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars. * @method $this notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.