SimpleArray   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A export() 0 12 3
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