PostOrderVisitor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 7
c 1
b 0
f 1
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 10 3
1
<?php
2
declare(strict_types=1);
3
/*
4
 * Copyright (C) 2019 Sebastian Böttger <[email protected]>
5
 * You may use, distribute and modify this code under the
6
 * terms of the MIT license.
7
 *
8
 * You should have received a copy of the MIT license with
9
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
10
 */
11
12
namespace Seboettg\Forest\Visitor;
13
14
use Seboettg\Collection\ArrayList;
15
use Seboettg\Collection\ArrayList\ArrayListInterface;
16
use Seboettg\Forest\General\TreeNodeInterface;
17
18
/**
19
 * Class PostOrderVisitor
20
 * Implements the tree traversal strategy Post-order.
21
 * In this traversal strategy, the root node is visited last. First we traverse the subtrees from left to right
22
 * and finally the root node.
23
 *
24
 * @package Seboettg\Forest\Visitor
25
 */
26
class PostOrderVisitor implements VisitorInterface
27
{
28
    /**
29
     * @param TreeNodeInterface $node
30
     * @return ArrayListInterface
31
     */
32 2
    public function visit(TreeNodeInterface $node): ArrayListInterface
33
    {
34 2
        $resultList = new ArrayList();
35 2
        if ($node !== null) {
36 2
            foreach($node->getChildren() as $child) {
37 2
                $resultList->merge($child->accept($this));
38
            }
39 2
            $resultList->append($node->getItem());
40
        }
41 2
        return $resultList;
42
    }
43
}
44