diff --git a/php-checks/src/main/java/org/sonar/php/checks/EmptyMethodCheck.java b/php-checks/src/main/java/org/sonar/php/checks/EmptyMethodCheck.java index fda79ae212..fd79d4d649 100644 --- a/php-checks/src/main/java/org/sonar/php/checks/EmptyMethodCheck.java +++ b/php-checks/src/main/java/org/sonar/php/checks/EmptyMethodCheck.java @@ -21,6 +21,7 @@ import org.sonar.check.Rule; import org.sonar.php.tree.TreeUtils; +import org.sonar.php.tree.impl.PHPTree; import org.sonar.plugins.php.api.tree.Tree.Kind; import org.sonar.plugins.php.api.tree.declaration.ClassDeclarationTree; import org.sonar.plugins.php.api.tree.declaration.FunctionDeclarationTree; @@ -47,7 +48,7 @@ public class EmptyMethodCheck extends PHPVisitorCheck { @Override public void visitMethodDeclaration(MethodDeclarationTree tree) { - if (tree.body().is(Kind.BLOCK) && !(hasValuableBody((BlockTree) tree.body()) || isClassAbstract(tree) || hasCommentAbove(tree.modifiers().get(0)))) { + if (tree.body().is(Kind.BLOCK) && !(hasValuableBody((BlockTree) tree.body()) || isClassAbstract(tree) || hasCommentAbove(((PHPTree) tree).getFirstToken()))) { commitIssue(tree, "method"); } @@ -56,7 +57,7 @@ public void visitMethodDeclaration(MethodDeclarationTree tree) { @Override public void visitFunctionDeclaration(FunctionDeclarationTree tree) { - if (!(hasValuableBody(tree.body()) || hasCommentAbove(tree.functionToken()))) { + if (!(hasValuableBody(tree.body()) || hasCommentAbove(((PHPTree) tree).getFirstToken()))) { commitIssue(tree, "function"); } diff --git a/php-checks/src/test/resources/checks/EmptyMethodCheck.php b/php-checks/src/test/resources/checks/EmptyMethodCheck.php index 37846bb1b9..b9dd690ec8 100644 --- a/php-checks/src/test/resources/checks/EmptyMethodCheck.php +++ b/php-checks/src/test/resources/checks/EmptyMethodCheck.php @@ -38,6 +38,9 @@ public function method10() { // Comment public function method11() {} // Compliant + + // Comment + function method11() {} // Compliant } abstract class AbstractClass {