diff --git a/src/Hal/Component/Ast/NodeTraverser.php b/src/Hal/Component/Ast/NodeTraverser.php index ec6e8fcd..4fe6909f 100644 --- a/src/Hal/Component/Ast/NodeTraverser.php +++ b/src/Hal/Component/Ast/NodeTraverser.php @@ -30,7 +30,7 @@ public function __construct(Mother $traverser, $stopCondition = null) { if(null === $stopCondition) { $stopCondition = function($node) { - if($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Interface_) { + if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Interface_) { return false; } @@ -96,47 +96,7 @@ public function traverseArray(array $nodes, array $visitors) { } if (PHP_VERSION_ID >= 70000) { - class NodeTraverser extends Mother - { - /** @var Traverser */ - private $traverser; - - public function __construct($cloneNodes = false, $stopCondition = null) - { - parent::__construct(); - $this->traverser = new Traverser($this, $stopCondition); - } - - public function traverseNode(Node $node): Node - { - return parent::traverseNode($node); - } - - protected function traverseArray(array $nodes): array - { - return $this->traverser->traverseArray($nodes, $this->visitors); - } - } + class_alias(Php7NodeTraverser::class, __NAMESPACE__ . '\\NodeTraverser'); } else { - class NodeTraverser extends Mother - { - /** @var Traverser */ - private $traverser; - - public function __construct($cloneNodes = false, $stopCondition = null) - { - parent::__construct(); - $this->traverser = new Traverser($this, $stopCondition); - } - - public function traverseNode(Node $node) - { - return parent::traverseNode($node); - } - - protected function traverseArray(array $nodes) - { - return $this->traverser->traverseArray($nodes, $this->visitors); - } - } -} \ No newline at end of file + class_alias(Php5NodeTraverser::class, __NAMESPACE__ . '\\NodeTraverser'); +} diff --git a/src/Hal/Component/Ast/Php5NodeTraverser.php b/src/Hal/Component/Ast/Php5NodeTraverser.php new file mode 100644 index 00000000..b4c64be9 --- /dev/null +++ b/src/Hal/Component/Ast/Php5NodeTraverser.php @@ -0,0 +1,26 @@ +traverser = new Traverser($this, $stopCondition); + } + + public function traverseNode(Node $node) + { + return parent::traverseNode($node); + } + + protected function traverseArray(array $nodes) + { + return $this->traverser->traverseArray($nodes, $this->visitors); + } +} diff --git a/src/Hal/Component/Ast/Php7NodeTraverser.php b/src/Hal/Component/Ast/Php7NodeTraverser.php new file mode 100644 index 00000000..45f1b6e2 --- /dev/null +++ b/src/Hal/Component/Ast/Php7NodeTraverser.php @@ -0,0 +1,27 @@ +traverser = new Traverser($this, $stopCondition); + } + + public function traverseNode(Node $node): Node + { + return parent::traverseNode($node); + } + + protected function traverseArray(array $nodes): array + { + return $this->traverser->traverseArray($nodes, $this->visitors); + } +} diff --git a/tests/Component/Ast/NodeTraverserTest.php b/tests/Component/Ast/NodeTraverserTest.php new file mode 100644 index 00000000..501b48f0 --- /dev/null +++ b/tests/Component/Ast/NodeTraverserTest.php @@ -0,0 +1,14 @@ +assertInstanceOf(BaseTraverser::class, new NodeTraverser()); + } +}