Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move nonnull type to public namespace #478

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading