Skip to content

Commit

Permalink
Move nonnull type to public namespace (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee authored Jun 10, 2024
1 parent ae3bf02 commit de979c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Psl/Internal/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<nonnull>
*
* @extends Type\Type<mixed>
*
* @internal
*/
final readonly class NonNullType extends Type\Type
{
Expand Down
10 changes: 4 additions & 6 deletions src/Psl/Type/nonnull.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

namespace Psl\Type;

use Psl\Type\Internal\NonNullType;

/**
* @psalm-pure
*
* @psalm-suppress ImpureStaticVariable - The $instance is always the same and is considered pure.
*
* @ara-return TypeInterface<nonnull>
* @ara-return NonNullType
*
* @return NonNullType
*/
function nonnull(): TypeInterface
function nonnull(): NonNullType
{
/** @var Internal\NonNullType $instance */
static $instance = new Internal\NonNullType();
/** @var NonNullType $instance */
static $instance = new NonNullType();

return $instance;
}

0 comments on commit de979c8

Please sign in to comment.