for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace loophp\phptree\Importer;
use Exception;
use loophp\phptree\Node\AttributeNode;
use loophp\phptree\Node\AttributeNodeInterface;
use loophp\phptree\Node\NodeInterface;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\Node\SourceFileNode;
/**
* Class MicrosoftTolerantPhpParser.
*/
final class MicrosoftTolerantPhpParser implements ImporterInterface
{
* @param SourceFileNode $data
*
* @throws Exception
* @return \loophp\phptree\Node\NodeInterface
public function import($data): NodeInterface
return $this->parseNode($data, (new AttributeNode(['label' => 'root'])));
}
* @param \Microsoft\PhpParser\Node $astNode
* @param \loophp\phptree\Node\AttributeNodeInterface $parent
* @return \loophp\phptree\Node\AttributeNodeInterface
private function parseNode(Node $astNode, AttributeNodeInterface $parent): AttributeNodeInterface
$node = new AttributeNode([
'label' => $astNode->getNodeKindName(),
'astNode' => $astNode,
]);
$parent->add($node);
foreach ($astNode->getChildNodes() as $child) {
$this->parseNode($child, $node);
return $parent;