Skip to content

Commit 0422ea8

Browse files
vhenzlondrejmirtes
authored andcommitted
Add support for interfaceExists
1 parent 978e524 commit 0422ea8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This extension specifies types of values passed to:
5454
* `Assert::notSame`
5555
* `Assert::implementsInterface`
5656
* `Assert::classExists`
57+
* `Assert::interfaceExists`
5758
* `Assert::minCount`
5859
* `Assert::inArray`
5960
* `Assert::oneOf`

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+6
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ private static function getExpressionResolvers(): array
377377
[$class]
378378
);
379379
},
380+
'interfaceExists' => function (Scope $scope, Arg $class): \PhpParser\Node\Expr {
381+
return new \PhpParser\Node\Expr\FuncCall(
382+
new \PhpParser\Node\Name('interface_exists'),
383+
[$class]
384+
);
385+
},
380386
'minCount' => function (Scope $scope, Arg $array, Arg $number): \PhpParser\Node\Expr {
381387
return new \PhpParser\Node\Expr\BinaryOp\GreaterOrEqual(
382388
new \PhpParser\Node\Expr\FuncCall(

tests/Type/WebMozartAssert/data/data.php

+3-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, $ad, $ae, $af, $ag, array $ah, $ai, $al, $am, $an, $ao, $ap, $aq, $ar)
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, $ag, array $ah, $ai, $al, $am, $an, $ao, $ap, $aq, $ar, $as)
1111
{
1212
\PHPStan\Testing\assertType('mixed', $a);
1313

@@ -178,6 +178,8 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
178178
Assert::minLength($ar, 1);
179179
\PHPStan\Testing\assertType('non-empty-string', $ar);
180180

181+
Assert::interfaceExists($ag);
182+
\PHPStan\Testing\assertType('class-string', $ag);
181183
}
182184

183185
}

0 commit comments

Comments
 (0)