Skip to content

Assert::implementsInterface($foo, <Type>) is incorrectly being translated to assert($foo instanceof <Type>) #18

@Ocramius

Description

@Ocramius

Assert::implementsInterface() works on object|string, not just object, so it should be translated to something like assert($foo instanceof $type || in_array($interface, \class_implements($value))) (see https://3v4l.org/VdIbR).

Not sure what the correct translation (understood by PHPStan) would be.

For reference, this is the current implementation:

'implementsInterface' => function (Scope $scope, Arg $expr, Arg $class): ?\PhpParser\Node\Expr {
$classType = $scope->getType($class->value);
if (!$classType instanceof ConstantStringType) {
return null;
}
return new \PhpParser\Node\Expr\Instanceof_(
$expr->value,
new \PhpParser\Node\Name($classType->getValue())
);
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions