Reverse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A modify() 0 10 2
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