File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © Magento, Inc. All rights reserved.
5+ * See COPYING.txt for license details.
6+ */
7+
8+ namespace Magento \SemanticVersionChecker \Visitor ;
9+
10+ use PhpParser \NodeVisitorAbstract ;
11+ use PhpParser \Node ;
12+
13+ /**
14+ * Create parent reference for nodes. Parent reference can be found in 'parent' node attribute.
15+ * TODO: Replace this class with lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php
16+ * after updating nikic/PHP-Parser to v4.7.0
17+ */
18+ class ParentConnector extends NodeVisitorAbstract
19+ {
20+ /**
21+ * Stack of nodes that used to create parent references
22+ *
23+ * @var array
24+ */
25+ private $ stack ;
26+
27+ /**
28+ * @inheritDoc
29+ */
30+ public function beginTraverse (array $ nodes )
31+ {
32+ $ this ->stack = [];
33+ }
34+
35+ /**
36+ * @inheritDoc
37+ */
38+ public function enterNode (Node $ node )
39+ {
40+ if (!empty ($ this ->stack )) {
41+ $ node ->setAttribute ('parent ' , $ this ->stack [count ($ this ->stack ) - 1 ]);
42+ }
43+ $ this ->stack [] = $ node ;
44+ }
45+
46+ /**
47+ * @inheritDoc
48+ */
49+ public function leaveNode (Node $ node )
50+ {
51+ array_pop ($ this ->stack );
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments