Inflate::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Vine\Commands;
4
5
use Vine\NodeCollection;
6
7
class Inflate
8
{
9
    /**
10
     * Return proper tree structure of flattened node collection.
11
     * Nodes from a flat collection retain their relations so
12
     * we just need to return the root nodes
13
     *
14
     * @param NodeCollection $flatCollection
15
     * @return NodeCollection
16
     */
17 6
    public function __invoke(NodeCollection $flatCollection): NodeCollection
18
    {
19 6
        $roots = new NodeCollection();
20
21 6
        foreach($flatCollection as $k => $node)
22
        {
23 6
            if($node->isRoot())
24
            {
25 6
                $roots->add($node);
26
            }
27
        }
28
29 6
        return $roots;
30
    }
31
}
32