Completed
Push — master ( 8fa2c2...1d12ed )
by WEBEWEB
01:31
created

NavigationTree::getBreadcrumbs()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 26
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 6.7272
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;
13
14
/**
15
 * Navigation tree.
16
 *
17
 * @author webeweb <https://github.com/webeweb/>
18
 * @package WBW\Bundle\BootstrapBundle\Navigation
19
 */
20
class NavigationTree extends AbstractNavigationNode {
21
22
    /**
23
     * Constructor.
24
     */
25
    public function __construct() {
26
        parent::__construct("tree");
27
    }
28
29
    /**
30
     * Get the breadcrumbs.
31
     *
32
     * @param AbstractNavigationNode $node The navigation node.
33
     * @return AsbtractNavigationNode[] Returns the navigation nodes.
34
     */
35
    public function getBreadcrumbs(AbstractNavigationNode $node = null) {
36
37
        // Create the breadcrumbs.
38
        $breadcrumbs = [];
39
40
        // Correct the parameter if necessary.
41
        if (null === $node) {
42
            $node = $this;
43
        }
44
45
        // Check the instance.
46
        if (true === ($node instanceof NavigationNode || $node instanceof BreadcrumbNode) && true === $node->getActive()) {
47
            $breadcrumbs[] = $node;
48
        }
49
50
        // Handle each node.
51
        foreach ($node->getNodes() as $current) {
52
            if (false === ($current instanceof AbstractNavigationNode)) {
53
                continue;
54
            }
55
            $breadcrumbs = array_merge($breadcrumbs, $this->getBreadcrumbs($current));
56
        }
57
58
        // Return the breadcrumbs.
59
        return $breadcrumbs;
60
    }
61
62
}
63