Reverse::modify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\phptree\Modifier;
11
12
use ArrayObject;
13
use loophp\phptree\Node\NodeInterface;
14
15
/**
16
 * Class Reverse.
17
 */
18
class Reverse implements ModifierInterface
19
{
20 1
    public function modify(NodeInterface $tree): NodeInterface
21
    {
22 1
        $children = new ArrayObject();
23
24 1
        foreach ($tree->children() as $child) {
25 1
            $children->append($this->modify($child));
26
        }
27
28 1
        return $tree->withChildren(...array_reverse(
29 1
            $children->getArrayCopy()
30
        ));
31
    }
32
}
33