Slice::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 8
cp 0.875
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 2
crap 4.0312
1
<?php
2
3
namespace Vine\Commands;
4
5
use Vine\Node;
6
use Vine\NodeCollection;
7
8
class Slice
9
{
10
    /**
11
     * Slice a node from the tree and return a new tree structure where
12
     * the children from this node get the parent of the extracted Node
13
     * as their parent
14
     *
15
     * @param NodeCollection $nodeCollection
16
     * @param Node[] $sliceNodes
17
     * @return NodeCollection
18
     */
19 24
    public function __invoke(NodeCollection $nodeCollection, Node ...$sliceNodes): NodeCollection
20
    {
21
        // Check if current node is one of the passed nodes to be sliced out
22 24
        foreach($sliceNodes as $node)
23
        {
24
            // Add children to parent of this node
25 18
            foreach($node->children() as $child)
0 ignored issues
show
Bug introduced by
The method children cannot be called on $node (of type array<integer,object<Vine\Node>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
26
            {
27 15
                ($node->isRoot())
0 ignored issues
show
Bug introduced by
The method isRoot cannot be called on $node (of type array<integer,object<Vine\Node>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
                    ? $child->moveToRoot()
29 15
                    : $child->move($node->parent());
0 ignored issues
show
Bug introduced by
The method parent cannot be called on $node (of type array<integer,object<Vine\Node>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
30
            }
31
32 18
            $node->remove();
0 ignored issues
show
Bug introduced by
The method remove cannot be called on $node (of type array<integer,object<Vine\Node>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
33
        }
34
35 24
        return $nodeCollection;
36
    }
37
}
38