Skip to content

Commit 490e043

Browse files
committed
check integrish values
1 parent 9ff202d commit 490e043

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+18
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ private static function getExpressionResolvers(): array
186186
[$value]
187187
);
188188
},
189+
'integrish' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
190+
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr(
191+
new \PhpParser\Node\Expr\BinaryOp\BooleanAnd(
192+
new \PhpParser\Node\Expr\FuncCall(
193+
new \PhpParser\Node\Name('is_string'),
194+
[$value]
195+
),
196+
new \PhpParser\Node\Expr\FuncCall(
197+
new \PhpParser\Node\Name('is_numeric'),
198+
[$value]
199+
)
200+
),
201+
new \PhpParser\Node\Expr\FuncCall(
202+
new \PhpParser\Node\Name('is_int'),
203+
[$value]
204+
)
205+
);
206+
},
189207
'numeric' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
190208
return new \PhpParser\Node\Expr\FuncCall(
191209
new \PhpParser\Node\Name('is_numeric'),

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function testExtension(): void
145145
'Variable $ab is: array<PHPStan\Type\WebMozartAssert\Foo>',
146146
113,
147147
],
148+
[
149+
'Variable $ac is: mixed',
150+
116,
151+
],
148152
]);
149153
}
150154

tests/Type/WebMozartAssert/data/data.php

+4-1
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)
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)
1111
{
1212
$a;
1313

@@ -111,6 +111,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
111111

112112
Assert::allSubclassOf($ab, self::class);
113113
$ab;
114+
115+
Assert::integrish($ac, self::class);
116+
$ac;
114117
}
115118

116119
}

0 commit comments

Comments
 (0)