Sonar PHP custom rules : How to get the name of the class owning a method which is called?

Viewed 33

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 : https://github.com/SonarSource/sonar-php/blob/master/php-frontend/src/main/java/org/sonar/php/symbols/MethodSymbol.java

0 Answers
Related