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

Added TruthyString #12

Merged
merged 1 commit into from
Sep 28, 2023
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
24 changes: 24 additions & 0 deletions src/TruthyString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Typhoon\Type;

/**
* @api
* @psalm-immutable
* @implements Type<truthy-string>
*/
enum TruthyString implements Type
{
/**
* @internal
* @psalm-internal Typhoon\Type
*/
case type;

public function accept(TypeVisitor $visitor): mixed
{
return $visitor->visitTruthyString($this);
}
}
3 changes: 3 additions & 0 deletions src/TypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function visitTraitString(TraitStringType $type): mixed;
/** @return TReturn */
public function visitNonEmptyString(NonEmptyStringType $type): mixed;

/** @return TReturn */
public function visitTruthyString(TruthyString $type): mixed;

/** @return TReturn */
public function visitString(StringType $type): mixed;

Expand Down
2 changes: 2 additions & 0 deletions src/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class types
public const enumString = EnumStringType::type;
public const traitString = TraitStringType::type;
public const nonEmptyString = NonEmptyStringType::type;
public const truthyString = TruthyString::type;
public const nonFalsyString = TruthyString::type;
public const string = StringType::type;
public const numeric = NumericType::type;
public const scalar = ScalarType::type;
Expand Down
12 changes: 12 additions & 0 deletions tests/psalm/TruthyStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Typhoon\Type\TruthyStringTest;

use Typhoon\Type\TruthyString;
use function Typhoon\Type\extractType;

/** @psalm-check-type-exact $_string = non-falsy-string */
/** @psalm-check-type-exact $_string = truthy-string */
$_string = extractType(TruthyString::type);