Completed
Push — master ( 494359...c0981b )
by WEBEWEB
01:47
created

NavigationTree::getBreadcrumbs()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 23
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
cc 6
eloc 9
nc 8
nop 1
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
			$breadcrumbs = array_merge($breadcrumbs, $this->getBreadcrumbs($current));
0 ignored issues
show
Documentation introduced by
$current is of type object<WBW\Library\Core\Node\AbstractNode>, but the function expects a null|object<WBW\Library\...AbstractNavigationNode>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
		}
59
60
		// Return the breadcrumbs.
61
		return $breadcrumbs;
62
	}
63
64
}
65