Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticMethodTypeSpecifyingExtension;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
Expand Down Expand Up @@ -302,10 +303,26 @@ private static function getExpressionResolvers(): array
},
'implementsInterface' => function (Scope $scope, Arg $expr, Arg $class): ?\PhpParser\Node\Expr {
$classType = $scope->getType($class->value);
$exprType = $scope->getType($expr->value);
if (!$classType instanceof ConstantStringType) {
return null;
}

if ($exprType instanceof StringType) {
return new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('in_array'),
[
$class,
new \PhpParser\Node\Arg(
new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('class_implements'),
[$expr]
)
),
]
);
}

return new \PhpParser\Node\Expr\Instanceof_(
$expr->value,
new \PhpParser\Node\Name($classType->getValue())
Expand Down
2 changes: 2 additions & 0 deletions tests/Type/WebMozartAssert/data/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,

Assert::implementsInterface($ae, Baz::class);
$ae;

Assert::implementsInterface(Bar::class, Foo::class);
}

}
Expand Down