Skip to content

Commit 27d5ff4

Browse files
simPodondrejmirtes
authored andcommitted
Add support for notFalse()
1 parent c3c84ec commit 27d5ff4

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use Webmozart\Assert;
1818

1919
function demo(?int $a) {
2020
// ...
21-
21+
2222
Assert::integer($a);
2323
// phpstan is now aware that $a can no longer be `null` at this point
24-
24+
2525
return ($a === 10);
2626
}
2727
```
@@ -47,6 +47,7 @@ This extension specifies types of values passed to:
4747
* `Assert::subclassOf`
4848
* `Assert::true`
4949
* `Assert::false`
50+
* `Assert::notFalse`
5051
* `Assert::null`
5152
* `Assert::notNull`
5253
* `Assert::same`

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ private static function getExpressionResolvers(): array
338338
new \PhpParser\Node\Expr\ConstFetch(new \PhpParser\Node\Name('null'))
339339
);
340340
},
341+
'notFalse' => static function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
342+
return new \PhpParser\Node\Expr\BinaryOp\NotIdentical(
343+
$expr->value,
344+
new \PhpParser\Node\Expr\ConstFetch(new \PhpParser\Node\Name('false'))
345+
);
346+
},
341347
'notNull' => function (Scope $scope, Arg $expr): \PhpParser\Node\Expr {
342348
return new \PhpParser\Node\Expr\BinaryOp\NotIdentical(
343349
$expr->value,

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public function testExtension(): void
160160
'Variable $ae is: PHPStan\Type\WebMozartAssert\Baz',
161161
122,
162162
],
163+
[
164+
'Variable $af is: int',
165+
126,
166+
],
163167
]);
164168
}
165169

tests/Type/WebMozartAssert/data/data.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Foo
88
{
99

10-
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae)
10+
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae, $af)
1111
{
1212
$a;
1313

@@ -120,6 +120,10 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
120120

121121
Assert::implementsInterface($ae, Baz::class);
122122
$ae;
123+
124+
/** @var int|false $af */
125+
Assert::notFalse($af);
126+
$af;
123127
}
124128

125129
}

0 commit comments

Comments
 (0)