nodeNameResolver = $nodeNameResolver; $this->binaryOpManipulator = $binaryOpManipulator; } public function processBooleanOr(BooleanOr $booleanOr, string $type, string $newMethodName): ?FuncCall { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanOr, Instanceof_::class, FuncCall::class ); if ($twoNodeMatch === null) { return null; } /** @var Instanceof_ $instanceOfNode */ $instanceOfNode = $twoNodeMatch->getFirstExpr(); /** @var FuncCall $funcCallNode */ $funcCallNode = $twoNodeMatch->getSecondExpr(); $instanceOfClass = $instanceOfNode->class; if ($instanceOfClass instanceof Expr) { return null; } if ((string) $instanceOfClass !== $type) { return null; } $nodeNameResolverGetName = $this->nodeNameResolver->getName($funcCallNode); if ($nodeNameResolverGetName !== 'is_array') { return null; } // both use same var if (! $funcCallNode->args[0]->value instanceof Variable) { return null; } /** @var Variable $firstVarNode */ $firstVarNode = $funcCallNode->args[0]->value; if (! $instanceOfNode->expr instanceof Variable) { return null; } /** @var Variable $secondVarNode */ $secondVarNode = $instanceOfNode->expr; // are they same variables if ($firstVarNode->name !== $secondVarNode->name) { return null; } return new FuncCall(new Name($newMethodName), [new Arg($firstVarNode)]); } }