Skip to content

Commit a5d6fa7

Browse files
mavimoondrejmirtes
authored andcommitted
check integrish values
1 parent 3c04ae2 commit a5d6fa7

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This extension specifies types of values passed to:
1414
* `Assert::stringNotEmpty`
1515
* `Assert::float`
1616
* `Assert::numeric`
17+
* `Assert::integerish`
1718
* `Assert::boolean`
1819
* `Assert::scalar`
1920
* `Assert::object`

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+18
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ private static function getExpressionResolvers(): array
192192
[$value]
193193
);
194194
},
195+
'integerish' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
196+
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr(
197+
new \PhpParser\Node\Expr\BinaryOp\BooleanAnd(
198+
new \PhpParser\Node\Expr\FuncCall(
199+
new \PhpParser\Node\Name('is_string'),
200+
[$value]
201+
),
202+
new \PhpParser\Node\Expr\FuncCall(
203+
new \PhpParser\Node\Name('is_numeric'),
204+
[$value]
205+
)
206+
),
207+
new \PhpParser\Node\Expr\FuncCall(
208+
new \PhpParser\Node\Name('is_int'),
209+
[$value]
210+
)
211+
);
212+
},
195213
'numeric' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
196214
return new \PhpParser\Node\Expr\FuncCall(
197215
new \PhpParser\Node\Name('is_numeric'),

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public function testExtension(): void
149149
'Variable $ac is: string',
150150
116,
151151
],
152+
[
153+
'Variable $ad is: int|string',
154+
119,
155+
],
152156
]);
153157
}
154158

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, $ac)
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)
1111
{
1212
$a;
1313

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

115115
Assert::stringNotEmpty($ac);
116116
$ac;
117+
118+
Assert::integerish($ad);
119+
$ad;
117120
}
118121

119122
}

0 commit comments

Comments
 (0)