Ancestors   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 4
1
<?php
2
3
namespace Vine\Queries;
4
5
use Vine\Node;
6
use Vine\NodeCollection;
7
8
class Ancestors
9
{
10
    /**
11
     * @param Node $node
12
     * @param null $depth
13
     * @return NodeCollection
14
     */
15 15
    public function __invoke(Node $node, $depth = null): NodeCollection
16
    {
17 15
        $ancestors = new NodeCollection;
18 15
        $currentDepth = 0;
19
20 15
        while($parent = $node->parent())
21
        {
22 15
            if(!is_null($depth) && $currentDepth >= $depth) break;
23 15
            $currentDepth++;
24
25 15
            $node = $parent;
26 15
            $ancestors->add($parent);
27
        }
28
29 15
        return new NodeCollection(...array_reverse($ancestors->all()));
30
    }
31
}
32