1616use PhpParser \Node \Expr \CallLike ;
1717use PhpParser \Node \Expr \Cast ;
1818use PhpParser \Node \Expr \Closure ;
19+ use PhpParser \Node \Expr \Match_ ;
1920use PhpParser \Node \Expr \MethodCall ;
2021use PhpParser \Node \Expr \NullsafePropertyFetch ;
2122use PhpParser \Node \Expr \PropertyFetch ;
2223use PhpParser \Node \Expr \StaticPropertyFetch ;
2324use PhpParser \Node \Expr \Ternary ;
25+ use PhpParser \Node \MatchArm ;
2426use PhpParser \Node \Scalar \Encapsed ;
2527use PhpParser \Node \Stmt \Break_ ;
2628use PhpParser \Node \Stmt \Case_ ;
2729use PhpParser \Node \Stmt \Catch_ ;
30+ use PhpParser \Node \Stmt \Class_ ;
31+ use PhpParser \Node \Stmt \ClassMethod ;
2832use PhpParser \Node \Stmt \Continue_ ;
2933use PhpParser \Node \Stmt \Do_ ;
3034use PhpParser \Node \Stmt \Echo_ ;
@@ -118,6 +122,30 @@ private function getLines(Node $node): array
118122 return [$ node ->dim ->getStartLine ()];
119123 }
120124
125+ if ($ node instanceof ClassMethod) {
126+ if ($ node ->name ->name !== '__construct ' ) {
127+ return [];
128+ }
129+
130+ $ existsAPromotedProperty = false ;
131+
132+ foreach ($ node ->getParams () as $ param ) {
133+ if (0 !== ($ param ->flags & Class_::VISIBILITY_MODIFIER_MASK )) {
134+ $ existsAPromotedProperty = true ;
135+
136+ break ;
137+ }
138+ }
139+
140+ if ($ existsAPromotedProperty ) {
141+ // Only the line with `function` keyword should be listed here
142+ // but `nikic/php-parser` doesn't provide a way to fetch it
143+ return range ($ node ->getStartLine (), $ node ->name ->getEndLine ());
144+ }
145+
146+ return [];
147+ }
148+
121149 if ($ node instanceof MethodCall) {
122150 return [$ node ->name ->getStartLine ()];
123151 }
@@ -134,6 +162,22 @@ private function getLines(Node $node): array
134162 return $ lines ;
135163 }
136164
165+ if ($ node instanceof Match_) {
166+ return [$ node ->cond ->getStartLine ()];
167+ }
168+
169+ if ($ node instanceof MatchArm) {
170+ return [$ node ->body ->getStartLine ()];
171+ }
172+
173+ if ($ node instanceof Expression && (
174+ $ node ->expr instanceof Cast ||
175+ $ node ->expr instanceof Match_ ||
176+ $ node ->expr instanceof MethodCall
177+ )) {
178+ return [];
179+ }
180+
137181 return [$ node ->getStartLine ()];
138182 }
139183
@@ -147,6 +191,7 @@ private function isExecutable(Node $node): bool
147191 $ node instanceof Case_ ||
148192 $ node instanceof Cast ||
149193 $ node instanceof Catch_ ||
194+ $ node instanceof ClassMethod ||
150195 $ node instanceof Closure ||
151196 $ node instanceof Continue_ ||
152197 $ node instanceof Do_ ||
@@ -160,6 +205,8 @@ private function isExecutable(Node $node): bool
160205 $ node instanceof Foreach_ ||
161206 $ node instanceof Goto_ ||
162207 $ node instanceof If_ ||
208+ $ node instanceof Match_ ||
209+ $ node instanceof MatchArm ||
163210 $ node instanceof MethodCall ||
164211 $ node instanceof NullsafePropertyFetch ||
165212 $ node instanceof PropertyFetch ||
0 commit comments