Hi,
to get the class owner of a method in a java custom rule, I do this :
private static class LoopBodyVisitor extends BaseTreeVisitor {
@Override
public void visitMethodInvocation(MethodInvocationTree methodInvocationTree) {
String className = methodInvocationTree.symbol().owner().name();
(...)
}
}
How can I get the class owning a method in PHP ? Is it even possible ?
Here is what I have so far :
private static class LoopBodyVisitor extends PHPVisitorCheck {
@Override
public void visitFunctionCall(FunctionCallTree functionCalltree) {
String className = functionCalltree. (???);
It looks like MethodSymbol exists with an “owner()” method, but I don’t know how to get this symbol inside visitors :
public interface MethodSymbol extends FunctionSymbol {
Visibility visibility();
String name();
Trilean isOverriding();
Trilean isAbstract();
ClassSymbol owner();
}
source : sonar-php/MethodSymbol.java at master · SonarSource/sonar-php · GitHub