Completed
Push — master ( 3c5d20...494359 )
by WEBEWEB
01:29
created

NavigationTree::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2017 NdC/WBW
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\Library\Core\Navigation\Tree;
13
14
use WBW\Library\Core\Navigation\Node\AbstractNavigationNode;
15
use WBW\Library\Core\Navigation\Node\BreadcrumbNode;
16
use WBW\Library\Core\Navigation\Node\NavigationNode;
17
18
/**
19
 * Navigation tree.
20
 *
21
 * @author NdC/WBW <https://github.com/webeweb/>
22
 * @package WBW\Library\Core\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 (is_null($node)) {
47
			$node = $this;
48
		}
49
50
		// Check the instance.
51
		if (($node instanceof NavigationNode || $node instanceof BreadcrumbNode) && $node->getActive()) {
52
			$breadcrumbs[] = $node;
53
		}
54
55
		// Handle each node.
56
		foreach ($node->getNodes() as $current) {
57
			if (($current instanceof AbstractNavigationNode) === false) {
58
				continue;
59
			}
60
			$breadcrumbs = array_merge($breadcrumbs, $this->getBreadcrumbs($current));
61
		}
62
63
		// Return the breadcrumbs.
64
		return $breadcrumbs;
65
	}
66
67
}
68