From df747f2f5649f4ba66cba0d8d09a9dc85c7c8fbb Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Sun, 9 Jun 2024 18:25:39 +0200 Subject: [PATCH] Move nonnull type to public namespace --- src/Psl/Internal/Loader.php | 2 +- src/Psl/Type/{Internal => }/NonNullType.php | 7 ++++--- src/Psl/Type/nonnull.php | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) rename src/Psl/Type/{Internal => }/NonNullType.php (86%) diff --git a/src/Psl/Internal/Loader.php b/src/Psl/Internal/Loader.php index 3ddf2f36..a2310df0 100644 --- a/src/Psl/Internal/Loader.php +++ b/src/Psl/Internal/Loader.php @@ -699,7 +699,7 @@ final class Loader 'Psl\\Type\\Internal\\IterableType' => 'Psl/Type/Internal/IterableType.php', 'Psl\\Type\\Internal\\MixedType' => 'Psl/Type/Internal/MixedType.php', 'Psl\\Type\\Internal\\NullType' => 'Psl/Type/Internal/NullType.php', - 'Psl\\Type\\Internal\\NonNullType' => 'Psl/Type/Internal/NonNullType.php', + 'Psl\\Type\\NonNullType' => 'Psl/Type/Internal/NonNullType.php', 'Psl\\Type\\Internal\\NullableType' => 'Psl/Type/Internal/NullableType.php', 'Psl\\Type\\Internal\\OptionalType' => 'Psl/Type/Internal/OptionalType.php', 'Psl\\Type\\Internal\\PositiveIntType' => 'Psl/Type/Internal/PositiveIntType.php', diff --git a/src/Psl/Type/Internal/NonNullType.php b/src/Psl/Type/NonNullType.php similarity index 86% rename from src/Psl/Type/Internal/NonNullType.php rename to src/Psl/Type/NonNullType.php index 3fc8a645..2864cc05 100644 --- a/src/Psl/Type/Internal/NonNullType.php +++ b/src/Psl/Type/NonNullType.php @@ -2,18 +2,19 @@ declare(strict_types=1); -namespace Psl\Type\Internal; +namespace Psl\Type; use Psl\Type; use Psl\Type\Exception\AssertException; use Psl\Type\Exception\CoercionException; /** + * This type is not marked as internal, cause the class is being leaked by the nonnull() function. + * This is necessary to get coerce and assert narrow down the type without psalm having a TNonNull type. + * * @ara-extends Type\Type * * @extends Type\Type - * - * @internal */ final readonly class NonNullType extends Type\Type { diff --git a/src/Psl/Type/nonnull.php b/src/Psl/Type/nonnull.php index 73f21159..99375230 100644 --- a/src/Psl/Type/nonnull.php +++ b/src/Psl/Type/nonnull.php @@ -4,8 +4,6 @@ namespace Psl\Type; -use Psl\Type\Internal\NonNullType; - /** * @psalm-pure * @@ -17,8 +15,8 @@ */ function nonnull(): TypeInterface { - /** @var Internal\NonNullType $instance */ - static $instance = new Internal\NonNullType(); + /** @var NonNullType $instance */ + static $instance = new NonNullType(); return $instance; }