diff --git a/src/Assert.php b/src/Assert.php index d65dd8a9..8e3f83f0 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -701,7 +701,8 @@ public static function false($value, $message = '') } /** - * @psalm-assert string $value + * @psalm-assert string|object $value note: can be an object implementing __toString + * @psalm-assert !empty $value * * @param mixed $value * @param string $message @@ -719,7 +720,8 @@ public static function ip($value, $message = '') } /** - * @psalm-assert string $value + * @psalm-assert string|object $value note: can be an object implementing __toString + * @psalm-assert !empty $value * * @param mixed $value * @param string $message @@ -737,7 +739,8 @@ public static function ipv4($value, $message = '') } /** - * @psalm-assert string $value + * @psalm-assert string|object $value note: can be an object implementing __toString + * @psalm-assert !empty $value * * @param mixed $value * @param string $message @@ -755,7 +758,8 @@ public static function ipv6($value, $message = '') } /** - * @psalm-assert string $value + * @psalm-assert string|object $value note: can be an object implementing __toString + * @psalm-assert !empty $value * * @param mixed $value * @param string $message diff --git a/tests/static-analysis/assert-email.php b/tests/static-analysis/assert-email.php index ed4a297f..dcb12bfc 100644 --- a/tests/static-analysis/assert-email.php +++ b/tests/static-analysis/assert-email.php @@ -4,10 +4,14 @@ use Webmozart\Assert\Assert; -/** - * @psalm-param mixed $value - */ -function consume($value): string +function consume(?string $value): string +{ + Assert::email($value); + + return $value; +} + +function consumeObject(?object $value): object { Assert::email($value); diff --git a/tests/static-analysis/assert-ip.php b/tests/static-analysis/assert-ip.php index d8df3372..534266ef 100644 --- a/tests/static-analysis/assert-ip.php +++ b/tests/static-analysis/assert-ip.php @@ -4,12 +4,17 @@ use Webmozart\Assert\Assert; -/** - * @psalm-param mixed $value - */ -function consume($value): string +function consume(?string $value): string { Assert::ip($value); return $value; } + +function consumeObject(?object $value): object +{ + Assert::ip($value); + + return $value; +} + diff --git a/tests/static-analysis/assert-ipv4.php b/tests/static-analysis/assert-ipv4.php index 338f8444..5c3b92dd 100644 --- a/tests/static-analysis/assert-ipv4.php +++ b/tests/static-analysis/assert-ipv4.php @@ -4,12 +4,17 @@ use Webmozart\Assert\Assert; -/** - * @psalm-param mixed $value - */ -function consume($value): string +function consume(?string $value): string { Assert::ipv4($value); return $value; } + +function consumeObject(?object $value): object +{ + Assert::ipv4($value); + + return $value; +} + diff --git a/tests/static-analysis/assert-ipv6.php b/tests/static-analysis/assert-ipv6.php index 374c577e..c2b2a6cf 100644 --- a/tests/static-analysis/assert-ipv6.php +++ b/tests/static-analysis/assert-ipv6.php @@ -4,12 +4,17 @@ use Webmozart\Assert\Assert; -/** - * @psalm-param mixed $value - */ -function consume($value): string +function consume(?string $value): string { Assert::ipv6($value); return $value; } + +function consumeObject(?object $value): object +{ + Assert::ipv6($value); + + return $value; +} +