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

NavigationTree   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
C 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
    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