Completed
Push — master ( 341a7d...fd15d4 )
by WEBEWEB
02:17
created

NavigationTree   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getBreadcrumbs() 0 26 7
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
     * @param $name The name.
26
     */
27
    public function __construct($name) {
28
        parent::__construct($name);
29
    }
30
31
    /**
32
     * Get the breadcrumbs.
33
     *
34
     * @param AbstractNavigationNode $node The navigation node.
35
     * @return AsbtractNavigationNode[] Returns the navigation nodes.
36
     */
37
    public function getBreadcrumbs(AbstractNavigationNode $node = null) {
38
39
        // Create the breadcrumbs.
40
        $breadcrumbs = [];
41
42
        // Correct the parameter if necessary.
43
        if (null === $node) {
44
            $node = $this;
45
        }
46
47
        // Check the instance.
48
        if (true === ($node instanceof NavigationNode || $node instanceof BreadcrumbNode) && true === $node->getActive()) {
49
            $breadcrumbs[] = $node;
50
        }
51
52
        // Handle each node.
53
        foreach ($node->getNodes() as $current) {
54
            if (false === ($current instanceof AbstractNavigationNode)) {
55
                continue;
56
            }
57
            $breadcrumbs = array_merge($breadcrumbs, $this->getBreadcrumbs($current));
58
        }
59
60
        // Return the breadcrumbs.
61
        return $breadcrumbs;
62
    }
63
64
}
65