Copy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A recursiveDepth() 0 16 4
1
<?php
2
3
namespace Vine\Commands;
4
5
use Vine\Node;
6
use Vine\NodeCollection;
7
8
class Copy
9
{
10
    /**
11
     * Keep in mind that Node::copy() utilises the Copy class when used with the depth parameter.
12
     * So here the Node::copy() must never be passed a param to avoid infinite call loop.
13
     *
14
     * @param Node $node
15
     * @param null $depth (null is infinite)
16
     * @return Node
17
     */
18 30
    public function __invoke(Node $node, $depth = null): Node
19
    {
20 30
        $copy = $node->isolatedCopy();
21
22 30
        return $copy->addChildren($this->recursiveDepth($node->children(), $depth));
23
    }
24
25
    /**
26
     * @param Node $node
0 ignored issues
show
Bug introduced by
There is no parameter named $node. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     * @param NodeCollection $children
0 ignored issues
show
Bug introduced by
There is no parameter named $children. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     * @param $depth
29
     * @param null|int $currentDepth
30
     * @return bool|Node
31
     */
32 30
    private function recursiveDepth(NodeCollection $nodeCollection, $depth = null, $currentDepth = 0)
33
    {
34 30
        if(!is_null($depth) && $depth <= $currentDepth) return new NodeCollection();
35
36 30
        $copyCollection = new NodeCollection();
37 30
        $currentDepth++;
38
39 30
        foreach($nodeCollection as $node)
40
        {
41 30
            $copyCollection->add($subNode = $node->isolatedCopy());
42
43 30
            $subNode->addChildren($this->recursiveDepth($node->children(), $depth, $currentDepth));
44
        }
45
46 30
        return $copyCollection;
47
    }
48
}
49