Skip to content

Commit

Permalink
Merge pull request #6 from faissaloux/asBool-type-test
Browse files Browse the repository at this point in the history
`asBool()`  type test
  • Loading branch information
nunomaduro authored Mar 30, 2024
2 parents e0281e5 + 3f9fba7 commit b2608c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function asInt(): int

/**
* Asserts and narrow down the type to boolean.
*
* @phpstan-assert-if-true bool $this->variable
*/
public function asBool(): bool
{
Expand Down
8 changes: 8 additions & 0 deletions types/AsBoolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

use function PHPStan\Testing\assertType;

$variable = random_int(0, 1) ? 'string' : true;
assertType('bool', type($variable)->asBool());

0 comments on commit b2608c4

Please sign in to comment.