Completed
Push — master ( cd5eb5...60c610 )
by WEBEWEB
08:13
created

NavigationTree::getBreadcrumbs()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 26
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 6.7272
c 1
b 0
f 0
cc 7
eloc 11
nc 12
nop 1
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Navigation\Tree;
13
14
use WBW\Bundle\BootstrapBundle\Navigation\Node\AbstractNavigationNode;
15
use WBW\Bundle\BootstrapBundle\Navigation\Node\BreadcrumbNode;
16
use WBW\Bundle\BootstrapBundle\Navigation\Node\NavigationNode;
17
18
/**
19
 * Navigation tree.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Navigation\Tree
23
 * @final
24
 */
25
final class NavigationTree extends AbstractNavigationNode {
26
27
    /**
28
     * Constructor.
29
     */
30
    public function __construct() {
31
        parent::__construct("tree");
32
    }
33
34
    /**
35
     * Get the breadcrumbs.
36
     *
37
     * @param AbstractNavigationNode $node The navigation node.
38
     * @return AsbtractNavigationNode[] Returns the navigation nodes.
39
     */
40
    public function getBreadcrumbs(AbstractNavigationNode $node = null) {
41
42
        // Create the breadcrumbs.
43
        $breadcrumbs = [];
44
45
        // Correct the parameter if necessary.
46
        if (null === $node) {
47
            $node = $this;
48
        }
49
50
        // Check the instance.
51
        if (true === ($node instanceof NavigationNode || $node instanceof BreadcrumbNode) && true === $node->getActive()) {
52
            $breadcrumbs[] = $node;
53
        }
54
55
        // Handle each node.
56
        foreach ($node->getNodes() as $current) {
57
            if (false === ($current instanceof AbstractNavigationNode)) {
58
                continue;
59
            }
60
            $breadcrumbs = array_merge($breadcrumbs, $this->getBreadcrumbs($current));
61
        }
62
63
        // Return the breadcrumbs.
64
        return $breadcrumbs;
65
    }
66
67
}
68