MBHFramework/structures

View on GitHub
Mbh/Tree/Visitor/PostOrder.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 PostOrder extends Visitor
{
    public function visit(NodeInterface $node)
    {
        $nodes = [];
        foreach ($node->getChildren() as $child) {
            $nodes = array_merge(
                $nodes,
                $child->accept($this)
            );
        }

        $nodes[] = $node;

        return $nodes;
    }
}