> */ public function getNodeTypes() : array { return [FuncCall::class]; } /** * @param FuncCall $node */ public function refactor(Node $node) : ?Node { if (!$this->isName($node->name, 'is_a')) { return null; } if ($node->isFirstClassCallable()) { return null; } $args = $node->getArgs(); $firstArgValue = $args[0]->value; if (!$this->isFirstObjectType($firstArgValue)) { return null; } /** * instanceof with Variable is ok, while on FuncCal with instanceof cause fatal error, see https://3v4l.org/IHb30 */ if ($args[1]->value instanceof Variable) { return new Instanceof_($firstArgValue, $args[1]->value); } $className = $this->resolveClassName($args[1]->value); if ($className === null) { return null; } return new Instanceof_($firstArgValue, new FullyQualified($className)); } private function resolveClassName(Expr $expr) : ?string { if (!$expr instanceof ClassConstFetch) { return null; } $type = $this->getType($expr); if ($type instanceof GenericClassStringType) { $type = $type->getGenericType(); } if (!$type instanceof TypeWithClassName) { return null; } return $type->getClassName(); } private function isFirstObjectType(Expr $expr) : bool { $exprType = $this->getType($expr); if ($exprType instanceof ObjectWithoutClassType) { return \true; } return $exprType instanceof ObjectType; } }