Skip to content

Commit

Permalink
Added TruthyString
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Sep 28, 2023
1 parent 71e5be0 commit 1e0b789
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
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);

0 comments on commit 1e0b789

Please sign in to comment.