Conditions | 4 |
Paths | 2 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
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 |