1010namespace SebastianBergmann \CodeCoverage \StaticAnalysis ;
1111
1212use PhpParser \Node ;
13+ use PhpParser \Node \Expr \Assign ;
1314use PhpParser \Node \Expr \BinaryOp ;
1415use PhpParser \Node \Expr \CallLike ;
16+ use PhpParser \Node \Expr \Closure ;
17+ use PhpParser \Node \Expr \NullsafePropertyFetch ;
18+ use PhpParser \Node \Expr \PropertyFetch ;
19+ use PhpParser \Node \Expr \StaticPropertyFetch ;
20+ use PhpParser \Node \Expr \Ternary ;
1521use PhpParser \Node \Scalar ;
1622use PhpParser \Node \Stmt \Break_ ;
1723use PhpParser \Node \Stmt \Case_ ;
@@ -59,13 +65,13 @@ public function enterNode(Node $node): void
5965 return ;
6066 }
6167
62- $ line = $ this ->getLine ($ node );
68+ foreach ($ this ->getLines ($ node ) as $ line ) {
69+ if (isset ($ this ->propertyLines [$ line ])) {
70+ return ;
71+ }
6372
64- if (isset ($ this ->propertyLines [$ line ])) {
65- return ;
73+ $ this ->executableLines [$ line ] = $ line ;
6674 }
67-
68- $ this ->executableLines [$ line ] = $ line ;
6975 }
7076
7177 /**
@@ -87,47 +93,60 @@ private function savePropertyLines(Node $node): void
8793 }
8894 }
8995
90- private function getLine (Node $ node ): int
96+ /**
97+ * @return int[]
98+ */
99+ private function getLines (Node $ node ): array
91100 {
92101 if (
93- $ node instanceof Node \ Expr \ PropertyFetch ||
94- $ node instanceof Node \ Expr \ NullsafePropertyFetch ||
95- $ node instanceof Node \ Expr \ StaticPropertyFetch
102+ $ node instanceof PropertyFetch ||
103+ $ node instanceof NullsafePropertyFetch ||
104+ $ node instanceof StaticPropertyFetch
96105 ) {
97- return $ node ->getEndLine ();
106+ return [ $ node ->getEndLine ()] ;
98107 }
99108
100- return $ node ->getStartLine ();
109+ if ($ node instanceof Ternary) {
110+ return [
111+ $ node ->cond ->getStartLine (),
112+ $ node ->if ->getStartLine (),
113+ $ node ->else ->getStartLine (),
114+ ];
115+ }
116+
117+ return [$ node ->getStartLine ()];
101118 }
102119
103120 private function isExecutable (Node $ node ): bool
104121 {
105- return $ node instanceof BinaryOp ||
122+ return $ node instanceof Assign ||
123+ $ node instanceof BinaryOp ||
106124 $ node instanceof Break_ ||
107125 $ node instanceof CallLike ||
108126 $ node instanceof Case_ ||
109127 $ node instanceof Catch_ ||
128+ $ node instanceof Closure ||
110129 $ node instanceof Continue_ ||
111130 $ node instanceof Do_ ||
112131 $ node instanceof Echo_ ||
113132 $ node instanceof ElseIf_ ||
114133 $ node instanceof Else_ ||
115134 $ node instanceof Expression ||
116135 $ node instanceof Finally_ ||
117- $ node instanceof Foreach_ ||
118136 $ node instanceof For_ ||
137+ $ node instanceof Foreach_ ||
119138 $ node instanceof Goto_ ||
120139 $ node instanceof If_ ||
140+ $ node instanceof NullsafePropertyFetch ||
141+ $ node instanceof PropertyFetch ||
121142 $ node instanceof Return_ ||
122143 $ node instanceof Scalar ||
144+ $ node instanceof StaticPropertyFetch ||
123145 $ node instanceof Switch_ ||
146+ $ node instanceof Ternary ||
124147 $ node instanceof Throw_ ||
125148 $ node instanceof TryCatch ||
126149 $ node instanceof Unset_ ||
127- $ node instanceof Node \Expr \Assign ||
128- $ node instanceof Node \Expr \PropertyFetch ||
129- $ node instanceof Node \Expr \NullsafePropertyFetch ||
130- $ node instanceof Node \Expr \StaticPropertyFetch ||
131150 $ node instanceof While_;
132151 }
133152}
0 commit comments