Passed
Push — 1.x ( 0de076...576e4e )
by Ulises Jeremias
02:50
created

InOrder::visit()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php namespace Mbh\Tree\Visitor;
2
3
use Mbh\Tree\Interfaces\Node as NodeInterface;
4
use Mbh\Tree\Visitor;
5
6 View Code Duplication
class InOrder extends Visitor
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
{
8
    public function visit(NodeInterface $node)
9
    {
10
        if ($node->isLeaf()) {
11
            return [$node];
12
        }
13
14
        $yield = [];
15
16
        foreach ($node->getChildren() as $child) {
17
            $yield = array_merge($yield, $child->accept($this));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $child->accept($this) targeting Mbh\Tree\Interfaces\Node::accept() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
$child->accept($this) of type void is incompatible with the type null|array expected by parameter $array2 of array_merge(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
            $yield = array_merge($yield, /** @scrutinizer ignore-type */ $child->accept($this));
Loading history...
18
        }
19
20
        return $yield;
21
    }
22
}
23