Skip to content

Commit 2a16259

Browse files
Do not process children of ClassMethod and Function_ nodes
1 parent 3b2714e commit 2a16259

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/IgnoredLinesFindingVisitor.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PhpParser\Node\Stmt\ClassMethod;
1818
use PhpParser\Node\Stmt\Function_;
1919
use PhpParser\Node\Stmt\Trait_;
20+
use PhpParser\NodeTraverser;
2021
use PhpParser\NodeVisitorAbstract;
2122

2223
final class IgnoredLinesFindingVisitor extends NodeVisitorAbstract
@@ -36,19 +37,19 @@ public function __construct(bool $ignoreDeprecated)
3637
$this->ignoreDeprecated = $ignoreDeprecated;
3738
}
3839

39-
public function enterNode(Node $node): void
40+
public function enterNode(Node $node): ?int
4041
{
4142
if (!$node instanceof Class_ &&
4243
!$node instanceof Trait_ &&
4344
!$node instanceof ClassMethod &&
4445
!$node instanceof Function_) {
45-
return;
46+
return null;
4647
}
4748

4849
$docComment = $node->getDocComment();
4950

5051
if ($docComment === null) {
51-
return;
52+
return null;
5253
}
5354

5455
if (strpos($docComment->getText(), '@codeCoverageIgnore') !== false) {
@@ -64,6 +65,12 @@ public function enterNode(Node $node): void
6465
range($node->getStartLine(), $node->getEndLine())
6566
);
6667
}
68+
69+
if ($node instanceof ClassMethod || $node instanceof Function_) {
70+
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
71+
}
72+
73+
return null;
6774
}
6875

6976
/**

0 commit comments

Comments
 (0)