99 */
1010namespace SebastianBergmann \CodeCoverage \StaticAnalysis ;
1111
12+ use function array_diff_key ;
1213use function array_search ;
1314use function count ;
1415use function current ;
@@ -38,6 +39,8 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
3839 */
3940 private $ executableLinesGroupedByBranch = [];
4041
42+ private $ unsets = [];
43+
4144 public function __construct (string $ source )
4245 {
4346 $ this ->source = $ source ;
@@ -47,23 +50,39 @@ public function enterNode(Node $node): void
4750 {
4851 if ($ node instanceof Node \Stmt \Declare_ ||
4952 $ node instanceof Node \Stmt \DeclareDeclare ||
50- $ node instanceof Node \Stmt \Class_ ||
51- $ node instanceof Node \Stmt \ClassConst ||
5253 $ node instanceof Node \Stmt \Interface_ ||
54+ $ node instanceof Node \Stmt \Namespace_ ||
5355 $ node instanceof Node \Stmt \Nop ||
54- $ node instanceof Node \Stmt \Property ||
55- $ node instanceof Node \Stmt \PropertyProperty ||
56- $ node instanceof Node \Stmt \Trait_ ||
56+ $ node instanceof Node \Stmt \Use_ ||
57+ $ node instanceof Node \Stmt \UseUse ||
5758 $ node instanceof Node \Expr \Variable ||
59+ $ node instanceof Node \Name ||
5860 $ node instanceof Node \Param ||
5961 $ node instanceof Node \Const_ ||
6062 $ node instanceof Node \Scalar ||
61- $ node instanceof Node \Identifier ||
62- $ node instanceof Node \VarLikeIdentifier
63+ $ node instanceof Node \Identifier
6364 ) {
6465 return ;
6566 }
6667
68+ if ($ node instanceof Node \Stmt \Class_ ||
69+ $ node instanceof Node \Stmt \Trait_
70+ ) {
71+ foreach ($ node ->stmts as $ stmt ) {
72+ if ($ stmt instanceof Node \Stmt \ClassMethod ||
73+ $ stmt instanceof Node \Stmt \Nop
74+ ) {
75+ continue ;
76+ }
77+
78+ foreach (range ($ stmt ->getStartLine (), $ stmt ->getEndLine ()) as $ line ) {
79+ $ this ->unsets [$ line ] = true ;
80+ }
81+ }
82+
83+ return ;
84+ }
85+
6786 if ($ node instanceof Node \Expr \ArrowFunction) {
6887 $ startLine = max (
6988 $ node ->getStartLine () + 1 ,
@@ -292,6 +311,11 @@ public function afterTraverse(array $nodes): void
292311
293312 unset($ this ->executableLinesGroupedByBranch [1 + $ lineNumber ]);
294313 }
314+
315+ $ this ->executableLinesGroupedByBranch = array_diff_key (
316+ $ this ->executableLinesGroupedByBranch ,
317+ $ this ->unsets
318+ );
295319 }
296320
297321 public function executableLinesGroupedByBranch (): array
0 commit comments