MBHFramework/structures

View on GitHub
Mbh/Tree/Visitor/PreOrder.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php namespace Mbh\Tree\Visitor;

use Mbh\Tree\Interfaces\Node as NodeInterface;
use Mbh\Tree\Visitor;

class PreOrder extends Visitor
{
    public function visit(NodeInterface $node)
    {
        $nodes = [$node];

        foreach ($node->getChildren() as $child) {
            $nodes = array_merge(
                $nodes,
                $child->accept($this)
            );
        }

        return $nodes;
    }
}