From 33803d68fb985cd0876973c741bdbc86b8011757 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Sun, 12 Jan 2025 17:28:38 +0000 Subject: [PATCH 1/8] adds isStatic and isNotStatic # Conflicts: # src/Assert.php --- README.md | 8 ++-- src/Assert.php | 37 +++++++++++++++++ src/Mixin.php | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bbfac0a..ab70d34 100644 --- a/README.md +++ b/README.md @@ -212,9 +212,11 @@ Method | Description ### Function Assertions -Method | Description -------------------------------------------- | ----------------------------------------------------------------------------------------------------- -`throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. +Method | Description +-----------------------------------------------| ----------------------------------------------------------------------------------------------------- +`throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. +`isStatic($closure, $message = '')` | Check that a function is static. +`isNotStatic($closure, $message = '')` | Check that a function is not static. ### Collection Assertions diff --git a/src/Assert.php b/src/Assert.php index d585aa4..e1c3b52 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -17,6 +17,7 @@ use Countable; use DateTime; use DateTimeImmutable; +use ReflectionFunction; use ReflectionProperty; use Throwable; use Traversable; @@ -2042,6 +2043,42 @@ public static function isMap(mixed $array, string $message = ''): array return $array; } + /** + * @param Closure $closure + * @param string $message + * @return void + * @throws InvalidArgumentException + */ + public static function isStatic($closure, $message = '') + { + Assert::isCallable($closure); + $reflection = new ReflectionFunction($closure); + + if (! $reflection->isStatic()) { + static::reportInvalidArgument( + $message ?: 'Closure is not static.' + ); + } + } + + /** + * @param Closure $closure + * @param string $message + * @return void + * @throws InvalidArgumentException + */ + public static function isNotStatic($closure, $message = '') + { + Assert::isCallable($closure); + $reflection = new ReflectionFunction($closure); + + if ($reflection->isStatic()) { + static::reportInvalidArgument( + $message ?: 'Closure is not static.' + ); + } + } + /** * @psalm-pure * diff --git a/src/Mixin.php b/src/Mixin.php index c076c4e..7b0e09f 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4955,6 +4955,112 @@ public static function allNullOrIsMap(mixed $array, string $message = ''): mixed return $array; } + /** + * @param Closure|null $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function nullOrIsStatic($closure, $message = '') + { + null === $closure || static::isStatic($closure, $message); + } + + /** + * @param iterable $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function allIsStatic($closure, $message = '') + { + static::isIterable($closure); + + foreach ($closure as $entry) { + static::isStatic($entry, $message); + } + } + + /** + * @param iterable $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function allNullOrIsStatic($closure, $message = '') + { + static::isIterable($closure); + + foreach ($closure as $entry) { + null === $entry || static::isStatic($entry, $message); + } + } + + /** + * @param Closure|null $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function nullOrIsNotStatic($closure, $message = '') + { + null === $closure || static::isNotStatic($closure, $message); + } + + /** + * @param iterable $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function allIsNotStatic($closure, $message = '') + { + static::isIterable($closure); + + foreach ($closure as $entry) { + static::isNotStatic($entry, $message); + } + } + + /** + * @param iterable $closure + * @param string $message + * + * @return void + * + * @return void + * + * @throws InvalidArgumentException + */ + public static function allNullOrIsNotStatic($closure, $message = '') + { + static::isIterable($closure); + + foreach ($closure as $entry) { + null === $entry || static::isNotStatic($entry, $message); + } + } + /** * @psalm-pure * From b0ea6b858a2401c71d1f88abf90f323034dfe154 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Sun, 12 Jan 2025 17:41:35 +0000 Subject: [PATCH 2/8] Adds tests --- src/Assert.php | 2 +- src/Mixin.php | 6 ------ tests/AssertTest.php | 4 ++++ tests/static-analysis/assert-isStatic.php | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 tests/static-analysis/assert-isStatic.php diff --git a/src/Assert.php b/src/Assert.php index e1c3b52..3b15d8e 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -2054,7 +2054,7 @@ public static function isStatic($closure, $message = '') Assert::isCallable($closure); $reflection = new ReflectionFunction($closure); - if (! $reflection->isStatic()) { + if (!$reflection->isStatic()) { static::reportInvalidArgument( $message ?: 'Closure is not static.' ); diff --git a/src/Mixin.php b/src/Mixin.php index 7b0e09f..c94fe16 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4960,7 +4960,6 @@ public static function allNullOrIsMap(mixed $array, string $message = ''): mixed * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException @@ -4975,7 +4974,6 @@ public static function nullOrIsStatic($closure, $message = '') * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException @@ -4994,7 +4992,6 @@ public static function allIsStatic($closure, $message = '') * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException @@ -5013,7 +5010,6 @@ public static function allNullOrIsStatic($closure, $message = '') * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException @@ -5028,7 +5024,6 @@ public static function nullOrIsNotStatic($closure, $message = '') * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException @@ -5047,7 +5042,6 @@ public static function allIsNotStatic($closure, $message = '') * @param string $message * * @return void - * * @return void * * @throws InvalidArgumentException diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 4e801eb..b0ca992 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -621,6 +621,10 @@ public static function getTests(): array ['uniqueValues', [['qwerty', 'qwerty']], false], ['uniqueValues', [['asdfg', 'qwerty']], true], ['uniqueValues', [[123, '123']], false], + ['isStatic', [static function () {}], true], + ['isStatic', [function () {}], false], + ['isNotStatic', [static function () {}], false], + ['isNotStatic', [function () {}], true], ]; } diff --git a/tests/static-analysis/assert-isStatic.php b/tests/static-analysis/assert-isStatic.php new file mode 100644 index 0000000..2de93a5 --- /dev/null +++ b/tests/static-analysis/assert-isStatic.php @@ -0,0 +1,20 @@ + Date: Sun, 12 Jan 2025 17:43:17 +0000 Subject: [PATCH 3/8] fix readme table --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ab70d34..1aa3584 100644 --- a/README.md +++ b/README.md @@ -212,11 +212,11 @@ Method | Description ### Function Assertions -Method | Description ------------------------------------------------| ----------------------------------------------------------------------------------------------------- -`throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. -`isStatic($closure, $message = '')` | Check that a function is static. -`isNotStatic($closure, $message = '')` | Check that a function is not static. +Method | Description +------------------------------------------| ----------------------------------------------------------------------------------------------------- +`throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. +`isStatic($closure, $message = '')` | Check that a function is static. +`isNotStatic($closure, $message = '')` | Check that a function is not static. ### Collection Assertions From 750278c49a3176e7fd5a24f02ab34ccc1013c635 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Mon, 13 Jan 2025 20:37:02 +0000 Subject: [PATCH 4/8] type hint --- src/Assert.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 3b15d8e..1f14fe5 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -2049,9 +2049,8 @@ public static function isMap(mixed $array, string $message = ''): array * @return void * @throws InvalidArgumentException */ - public static function isStatic($closure, $message = '') + public static function isStatic(Closure $closure, $message = '') { - Assert::isCallable($closure); $reflection = new ReflectionFunction($closure); if (!$reflection->isStatic()) { @@ -2067,7 +2066,7 @@ public static function isStatic($closure, $message = '') * @return void * @throws InvalidArgumentException */ - public static function isNotStatic($closure, $message = '') + public static function isNotStatic(Closure $closure, $message = '') { Assert::isCallable($closure); $reflection = new ReflectionFunction($closure); From a30098d41284c8d87551ce48b3e72ef5b2b4f045 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Tue, 2 Dec 2025 01:06:22 +0000 Subject: [PATCH 5/8] wip --- src/Assert.php | 8 +++++--- tests/AssertTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 1f14fe5..6e1184a 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -14,6 +14,7 @@ namespace Webmozart\Assert; use ArrayAccess; +use Closure; use Countable; use DateTime; use DateTimeImmutable; @@ -2049,8 +2050,9 @@ public static function isMap(mixed $array, string $message = ''): array * @return void * @throws InvalidArgumentException */ - public static function isStatic(Closure $closure, $message = '') + public static function isStatic(mixed $closure, $message = '') { + static::isCallable($closure, $message); $reflection = new ReflectionFunction($closure); if (!$reflection->isStatic()) { @@ -2066,9 +2068,9 @@ public static function isStatic(Closure $closure, $message = '') * @return void * @throws InvalidArgumentException */ - public static function isNotStatic(Closure $closure, $message = '') + public static function isNotStatic(mixed $closure, $message = '') { - Assert::isCallable($closure); + static::isCallable($closure, $message); $reflection = new ReflectionFunction($closure); if ($reflection->isStatic()) { diff --git a/tests/AssertTest.php b/tests/AssertTest.php index b0ca992..44f9539 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -621,10 +621,10 @@ public static function getTests(): array ['uniqueValues', [['qwerty', 'qwerty']], false], ['uniqueValues', [['asdfg', 'qwerty']], true], ['uniqueValues', [[123, '123']], false], - ['isStatic', [static function () {}], true], - ['isStatic', [function () {}], false], - ['isNotStatic', [static function () {}], false], - ['isNotStatic', [function () {}], true], +// ['isStatic', [static function () {}], true], +// ['isStatic', [function () {}], false], +// ['isNotStatic', [static function () {}], false], +// ['isNotStatic', [function () {}], true], ]; } From 340e948136b489058cc531d09e3684bf0f630fc0 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Tue, 2 Dec 2025 01:21:17 +0000 Subject: [PATCH 6/8] fixes --- src/Assert.php | 15 +++++++++------ src/Mixin.php | 42 ++++++++++++++++++++++++------------------ tests/AssertTest.php | 8 ++++---- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 6e1184a..4c9128c 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -18,6 +18,7 @@ use Countable; use DateTime; use DateTimeImmutable; +use ReflectionException; use ReflectionFunction; use ReflectionProperty; use Throwable; @@ -2047,10 +2048,9 @@ public static function isMap(mixed $array, string $message = ''): array /** * @param Closure $closure * @param string $message - * @return void - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ - public static function isStatic(mixed $closure, $message = '') + public static function isStatic(mixed $closure, string $message = ''): Closure { static::isCallable($closure, $message); $reflection = new ReflectionFunction($closure); @@ -2060,15 +2060,16 @@ public static function isStatic(mixed $closure, $message = '') $message ?: 'Closure is not static.' ); } + + return $closure; } /** * @param Closure $closure * @param string $message - * @return void - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ - public static function isNotStatic(mixed $closure, $message = '') + public static function isNotStatic(mixed $closure, string $message = ''): Closure { static::isCallable($closure, $message); $reflection = new ReflectionFunction($closure); @@ -2078,6 +2079,8 @@ public static function isNotStatic(mixed $closure, $message = '') $message ?: 'Closure is not static.' ); } + + return $closure; } /** diff --git a/src/Mixin.php b/src/Mixin.php index c94fe16..202583d 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4959,100 +4959,106 @@ public static function allNullOrIsMap(mixed $array, string $message = ''): mixed * @param Closure|null $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function nullOrIsStatic($closure, $message = '') + public static function nullOrIsStatic(mixed $closure, string $message = ''): mixed { null === $closure || static::isStatic($closure, $message); + + return $closure; } /** * @param iterable $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function allIsStatic($closure, $message = '') + public static function allIsStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { static::isStatic($entry, $message); } + + return $closure; } /** * @param iterable $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function allNullOrIsStatic($closure, $message = '') + public static function allNullOrIsStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { null === $entry || static::isStatic($entry, $message); } + + return $closure; } /** * @param Closure|null $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function nullOrIsNotStatic($closure, $message = '') + public static function nullOrIsNotStatic(mixed $closure, string $message = ''): mixed { null === $closure || static::isNotStatic($closure, $message); + + return $closure; } /** * @param iterable $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function allIsNotStatic($closure, $message = '') + public static function allIsNotStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { static::isNotStatic($entry, $message); } + + return $closure; } /** * @param iterable $closure * @param string $message * - * @return void - * @return void + * @return mixed * * @throws InvalidArgumentException */ - public static function allNullOrIsNotStatic($closure, $message = '') + public static function allNullOrIsNotStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { null === $entry || static::isNotStatic($entry, $message); } + + return $closure; } /** diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 44f9539..b0ca992 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -621,10 +621,10 @@ public static function getTests(): array ['uniqueValues', [['qwerty', 'qwerty']], false], ['uniqueValues', [['asdfg', 'qwerty']], true], ['uniqueValues', [[123, '123']], false], -// ['isStatic', [static function () {}], true], -// ['isStatic', [function () {}], false], -// ['isNotStatic', [static function () {}], false], -// ['isNotStatic', [function () {}], true], + ['isStatic', [static function () {}], true], + ['isStatic', [function () {}], false], + ['isNotStatic', [static function () {}], false], + ['isNotStatic', [function () {}], true], ]; } From b7132982888b0d081ea00932e55e7b0aa9957d24 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Tue, 2 Dec 2025 23:54:46 +0000 Subject: [PATCH 7/8] fix mixin --- src/Mixin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Mixin.php b/src/Mixin.php index 202583d..d4449aa 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4961,7 +4961,7 @@ public static function allNullOrIsMap(mixed $array, string $message = ''): mixed * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function nullOrIsStatic(mixed $closure, string $message = ''): mixed { @@ -4976,7 +4976,7 @@ public static function nullOrIsStatic(mixed $closure, string $message = ''): mix * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function allIsStatic(mixed $closure, string $message = ''): mixed { @@ -4995,7 +4995,7 @@ public static function allIsStatic(mixed $closure, string $message = ''): mixed * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function allNullOrIsStatic(mixed $closure, string $message = ''): mixed { @@ -5014,7 +5014,7 @@ public static function allNullOrIsStatic(mixed $closure, string $message = ''): * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function nullOrIsNotStatic(mixed $closure, string $message = ''): mixed { @@ -5029,7 +5029,7 @@ public static function nullOrIsNotStatic(mixed $closure, string $message = ''): * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function allIsNotStatic(mixed $closure, string $message = ''): mixed { @@ -5048,7 +5048,7 @@ public static function allIsNotStatic(mixed $closure, string $message = ''): mix * * @return mixed * - * @throws InvalidArgumentException + * @throws InvalidArgumentException|ReflectionException */ public static function allNullOrIsNotStatic(mixed $closure, string $message = ''): mixed { From e327f6c83955b439f8b883bb3b7288d0ffcee281 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Wed, 3 Dec 2025 13:02:12 +0000 Subject: [PATCH 8/8] feedback changes --- README.md | 2 +- src/Assert.php | 23 ++++++-- src/Mixin.php | 66 ++++++++++++++-------- tests/AssertTest.php | 4 +- tests/static-analysis/assert-isStatic.php | 7 --- tests/static-analysis/assert-notStatic.php | 13 +++++ 6 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 tests/static-analysis/assert-notStatic.php diff --git a/README.md b/README.md index 1aa3584..7c10111 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ Method | Description ------------------------------------------| ----------------------------------------------------------------------------------------------------- `throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted. `isStatic($closure, $message = '')` | Check that a function is static. -`isNotStatic($closure, $message = '')` | Check that a function is not static. +`notStatic($closure, $message = '')` | Check that a function is not static. ### Collection Assertions diff --git a/src/Assert.php b/src/Assert.php index 4c9128c..6a7e345 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -18,7 +18,6 @@ use Countable; use DateTime; use DateTimeImmutable; -use ReflectionException; use ReflectionFunction; use ReflectionProperty; use Throwable; @@ -2047,8 +2046,14 @@ public static function isMap(mixed $array, string $message = ''): array /** * @param Closure $closure - * @param string $message - * @throws InvalidArgumentException|ReflectionException + * + * @psalm-pure + * + * @psalm-assert static Closure $closure + * + * @psalm-return static Closure + * + * @throws InvalidArgumentException */ public static function isStatic(mixed $closure, string $message = ''): Closure { @@ -2066,10 +2071,16 @@ public static function isStatic(mixed $closure, string $message = ''): Closure /** * @param Closure $closure - * @param string $message - * @throws InvalidArgumentException|ReflectionException + * + * @psalm-pure + * + * @psalm-assert Closure $closure + * + * @psalm-return Closure + * + * @throws InvalidArgumentException */ - public static function isNotStatic(mixed $closure, string $message = ''): Closure + public static function notStatic(mixed $closure, string $message = ''): Closure { static::isCallable($closure, $message); $reflection = new ReflectionFunction($closure); diff --git a/src/Mixin.php b/src/Mixin.php index d4449aa..0780cc8 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4957,11 +4957,14 @@ public static function allNullOrIsMap(mixed $array, string $message = ''): mixed /** * @param Closure|null $closure - * @param string $message * - * @return mixed + * @psalm-pure + * + * @psalm-assert static Closure|null $closure + * + * @return static Closure|null * - * @throws InvalidArgumentException|ReflectionException + * @throws InvalidArgumentException */ public static function nullOrIsStatic(mixed $closure, string $message = ''): mixed { @@ -4972,11 +4975,14 @@ public static function nullOrIsStatic(mixed $closure, string $message = ''): mix /** * @param iterable $closure - * @param string $message * - * @return mixed + * @psalm-pure + * + * @psalm-assert iterable $closure * - * @throws InvalidArgumentException|ReflectionException + * @return iterable + * + * @throws InvalidArgumentException */ public static function allIsStatic(mixed $closure, string $message = ''): mixed { @@ -4991,11 +4997,14 @@ public static function allIsStatic(mixed $closure, string $message = ''): mixed /** * @param iterable $closure - * @param string $message * - * @return mixed + * @psalm-pure * - * @throws InvalidArgumentException|ReflectionException + * @psalm-assert iterable $closure + * + * @return iterable + * + * @throws InvalidArgumentException */ public static function allNullOrIsStatic(mixed $closure, string $message = ''): mixed { @@ -5010,33 +5019,39 @@ public static function allNullOrIsStatic(mixed $closure, string $message = ''): /** * @param Closure|null $closure - * @param string $message * - * @return mixed + * @psalm-pure + * + * @psalm-assert Closure|null $closure + * + * @return Closure|null * - * @throws InvalidArgumentException|ReflectionException + * @throws InvalidArgumentException */ - public static function nullOrIsNotStatic(mixed $closure, string $message = ''): mixed + public static function nullOrNotStatic(mixed $closure, string $message = ''): mixed { - null === $closure || static::isNotStatic($closure, $message); + null === $closure || static::notStatic($closure, $message); return $closure; } /** * @param iterable $closure - * @param string $message * - * @return mixed + * @psalm-pure + * + * @psalm-assert iterable $closure * - * @throws InvalidArgumentException|ReflectionException + * @return iterable + * + * @throws InvalidArgumentException */ - public static function allIsNotStatic(mixed $closure, string $message = ''): mixed + public static function allNotStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { - static::isNotStatic($entry, $message); + static::notStatic($entry, $message); } return $closure; @@ -5044,18 +5059,21 @@ public static function allIsNotStatic(mixed $closure, string $message = ''): mix /** * @param iterable $closure - * @param string $message * - * @return mixed + * @psalm-pure * - * @throws InvalidArgumentException|ReflectionException + * @psalm-assert iterable $closure + * + * @return iterable + * + * @throws InvalidArgumentException */ - public static function allNullOrIsNotStatic(mixed $closure, string $message = ''): mixed + public static function allNullOrNotStatic(mixed $closure, string $message = ''): mixed { static::isIterable($closure); foreach ($closure as $entry) { - null === $entry || static::isNotStatic($entry, $message); + null === $entry || static::notStatic($entry, $message); } return $closure; diff --git a/tests/AssertTest.php b/tests/AssertTest.php index b0ca992..7ec8c6f 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -623,8 +623,8 @@ public static function getTests(): array ['uniqueValues', [[123, '123']], false], ['isStatic', [static function () {}], true], ['isStatic', [function () {}], false], - ['isNotStatic', [static function () {}], false], - ['isNotStatic', [function () {}], true], + ['notStatic', [static function () {}], false], + ['notStatic', [function () {}], true], ]; } diff --git a/tests/static-analysis/assert-isStatic.php b/tests/static-analysis/assert-isStatic.php index 2de93a5..d24cf02 100644 --- a/tests/static-analysis/assert-isStatic.php +++ b/tests/static-analysis/assert-isStatic.php @@ -11,10 +11,3 @@ function isStatic(Closure $closure): Closure return $closure; } - -function isNotStatic(Closure $closure): Closure -{ - Assert::isNotStatic($closure); - - return $closure; -} diff --git a/tests/static-analysis/assert-notStatic.php b/tests/static-analysis/assert-notStatic.php new file mode 100644 index 0000000..033335c --- /dev/null +++ b/tests/static-analysis/assert-notStatic.php @@ -0,0 +1,13 @@ +