Skip to content

Commit 939b70d

Browse files
committed
Add a empty alias for noContent
1 parent fd82f4c commit 939b70d

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Assertion::digit(mixed $value);
198198
Assertion::directory(string $value);
199199
Assertion::e164(string $value);
200200
Assertion::email(mixed $value);
201+
Assertion::empty(mixed $value);
201202
Assertion::endsWith(mixed $string, string $needle);
202203
Assertion::eq(mixed $value, mixed $value2);
203204
Assertion::extensionLoaded(mixed $value);

lib/Assert/Assertion.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @method static bool allDirectory(string $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists for all values.
3939
* @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.
4040
* @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.
41+
* @method static bool allEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values.
4142
* @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.
4243
* @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.
4344
* @method static bool allExtensionLoaded(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded for all values.
@@ -77,7 +78,7 @@
7778
* @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.
7879
* @method static bool allMinCount(array|\Countable|\ResourceBundle|\SimpleXMLElement $countable, int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements for all values.
7980
* @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.
80-
* @method static bool allNoContent(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty for all values.
81+
* @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.
8182
* @method static bool allNotBlank(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank for all values.
8283
* @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.
8384
* @method static bool allNotEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty for all values.
@@ -125,6 +126,7 @@
125126
* @method static bool nullOrDirectory(string $value, string|callable $message = null, string $propertyPath = null) Assert that a directory exists or that the value is null.
126127
* @method static bool nullOrE164(string $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.
127128
* @method static bool nullOrEmail(mixed $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.
129+
* @method static bool nullOrEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty or that the value is null.
128130
* @method static bool nullOrEndsWith(mixed $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.
129131
* @method static bool nullOrEq(mixed $value, mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==) or that the value is null.
130132
* @method static bool nullOrExtensionLoaded(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that extension is loaded or that the value is null.
@@ -164,7 +166,7 @@
164166
* @method static bool nullOrMin(mixed $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.
165167
* @method static bool nullOrMinCount(array|\Countable|\ResourceBundle|\SimpleXMLElement $countable, int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements or that the value is null.
166168
* @method static bool nullOrMinLength(mixed $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.
167-
* @method static bool nullOrNoContent(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is empty or that the value is null.
169+
* @method static bool nullOrNoContent(mixed $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.
168170
* @method static bool nullOrNotBlank(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not blank or that the value is null.
169171
* @method static bool nullOrNotContains(mixed $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.
170172
* @method static bool nullOrNotEmpty(mixed $value, string|callable $message = null, string $propertyPath = null) Assert that value is not empty or that the value is null.
@@ -589,7 +591,7 @@ public static function notEmpty($value, $message = null, $propertyPath = null)
589591
*
590592
* @return bool
591593
*/
592-
public static function noContent($value, $message = null, $propertyPath = null)
594+
public static function empty($value, $message = null, $propertyPath = null)
593595
{
594596
if (!empty($value)) {
595597
$message = \sprintf(
@@ -603,6 +605,22 @@ public static function noContent($value, $message = null, $propertyPath = null)
603605
return true;
604606
}
605607

608+
/**
609+
* Assert that value is empty.
610+
*
611+
* This is an alias of {@see empty()}.
612+
*
613+
* @param mixed $value
614+
* @param string|callable|null $message
615+
* @param string|null $propertyPath
616+
*
617+
* @return bool
618+
*/
619+
public static function noContent($value, $message = null, $propertyPath = null)
620+
{
621+
return static::empty($value, $message, $propertyPath);
622+
}
623+
606624
/**
607625
* Assert that value is null.
608626
*

lib/Assert/AssertionChain.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* @method AssertionChain directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists.
4040
* @method AssertionChain e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number.
4141
* @method AssertionChain email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL).
42+
* @method AssertionChain empty(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
4243
* @method AssertionChain endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars.
4344
* @method AssertionChain eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==).
4445
* @method AssertionChain extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded.
@@ -78,7 +79,7 @@
7879
* @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.
7980
* @method AssertionChain minCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
8081
* @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.
81-
* @method AssertionChain noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
82+
* @method AssertionChain noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of Assertion::empty().
8283
* @method AssertionChain notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank.
8384
* @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.
8485
* @method AssertionChain notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.

lib/Assert/LazyAssertion.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @method LazyAssertion directory(string|callable $message = null, string $propertyPath = null) Assert that a directory exists.
3939
* @method LazyAssertion e164(string|callable $message = null, string $propertyPath = null) Assert that the given string is a valid E164 Phone Number.
4040
* @method LazyAssertion email(string|callable $message = null, string $propertyPath = null) Assert that value is an email address (using input_filter/FILTER_VALIDATE_EMAIL).
41+
* @method LazyAssertion empty(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
4142
* @method LazyAssertion endsWith(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string ends with a sequence of chars.
4243
* @method LazyAssertion eq(mixed $value2, string|callable $message = null, string $propertyPath = null) Assert that two values are equal (using ==).
4344
* @method LazyAssertion extensionLoaded(string|callable $message = null, string $propertyPath = null) Assert that extension is loaded.
@@ -77,7 +78,7 @@
7778
* @method LazyAssertion min(mixed $minValue, string|callable $message = null, string $propertyPath = null) Assert that a value is at least as big as a given limit.
7879
* @method LazyAssertion minCount(int $count, string $message = null, string $propertyPath = null) Assert that the countable have at least $count elements.
7980
* @method LazyAssertion minLength(int $minLength, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that a string is at least $minLength chars long.
80-
* @method LazyAssertion noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty.
81+
* @method LazyAssertion noContent(string|callable $message = null, string $propertyPath = null) Assert that value is empty. This is an alias of Assertion::empty().
8182
* @method LazyAssertion notBlank(string|callable $message = null, string $propertyPath = null) Assert that value is not blank.
8283
* @method LazyAssertion notContains(string $needle, string|callable $message = null, string $propertyPath = null, string $encoding = 'utf8') Assert that string does not contains a sequence of chars.
8384
* @method LazyAssertion notEmpty(string|callable $message = null, string $propertyPath = null) Assert that value is not empty.

0 commit comments

Comments
 (0)