SimpleArray::export()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 10
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\Exporter;
11
12
use loophp\phptree\Node\NodeInterface;
13
14
/**
15
 * Class SimpleArray.
16
 */
17
final class SimpleArray implements ExporterInterface
18
{
19 2
    public function export(NodeInterface $node): array
20
    {
21 2
        $children = [];
22
23
        /** @var NodeInterface $child */
24 2
        foreach ($node->children() as $child) {
25 2
            $children[] = $this->export($child);
26
        }
27
28 2
        return [] === $children ?
29 2
            ['value' => $node->label()] :
30 2
            ['value' => $node->label(), 'children' => $children];
31
    }
32
}
33