File tree Expand file tree Collapse file tree 1 file changed +6
-27
lines changed
src/FeatureCounter/NodeVisitor Expand file tree Collapse file tree 1 file changed +6
-27
lines changed Original file line number Diff line number Diff line change 55use PhpParser \Node ;
66use PhpParser \Node \Expr \Throw_ ;
77use PhpParser \Node \Stmt \Expression ;
8+ use PhpParser \NodeVisitor ;
89use PhpParser \NodeVisitorAbstract ;
910
10- use function array_pop ;
11- use function count ;
12-
1311final class ThrowExpressionFlaggingNodeVisitor extends NodeVisitorAbstract {
14- /**
15- * @var Node[]
16- */
17- private array $ stack = [];
18-
19- public function beforeTraverse (array $ nodes ) {
20- $ this ->stack = [];
21-
22- return null ;
23- }
24-
2512 public function enterNode (Node $ node ) {
26- if ($ node instanceof Throw_ && ! empty ($ this ->stack )) {
27- $ parent = $ this ->stack [count ($ this ->stack ) - 1 ];
28-
29- if (! $ parent instanceof Expression) {
30- $ node ->setAttribute ('is_throw_expression ' , true );
31- }
13+ if ($ node instanceof Expression && $ node ->expr instanceof Throw_) {
14+ return NodeVisitor::DONT_TRAVERSE_CHILDREN ;
3215 }
3316
34- $ this ->stack [] = $ node ;
35-
36- return null ;
37- }
38-
39- public function leaveNode (Node $ node ) {
40- array_pop ($ this ->stack );
17+ if ($ node instanceof Throw_) {
18+ $ node ->setAttribute ('is_throw_expression ' , true );
19+ }
4120
4221 return null ;
4322 }
You can’t perform that action at this time.
0 commit comments