Skip to content

Commit 45b6a45

Browse files
committed
MC-38665: Magento SVC does not work for Magento 2.3.x when nikic/php-parser version is above 4.6.0
1 parent f70e324 commit 45b6a45

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/Visitor/ParentConnector.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)