Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MenuItem
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\HtmlBuilders\Components\Layout;
3
4use Apie\Common\MenuStructure\MenuNode;
5use Apie\HtmlBuilders\Components\BaseComponent;
6use Apie\HtmlBuilders\Lists\ComponentHashmap;
7
8class MenuItem extends BaseComponent
9{
10    /**
11     * @param array<int, string> $currentPath
12     */
13    public function __construct(
14        MenuNode $menuItem,
15        array $currentPath = [],
16        int $index = 0
17    ) {
18        $components = [];
19        foreach ($menuItem->children as $path => $child) {
20            $components[] = new MenuItem($child, [...$currentPath, $path], $index + 1);
21        }
22        parent::__construct(
23            [
24                'index' => $index,
25                'id' => $menuItem->id,
26                'name' => $menuItem->name,
27                'route' => $menuItem->route,
28                'icon' => $menuItem->icon,
29                'allowed' => $menuItem->allowed,
30                'subcomponents' => array_keys($components),
31            ],
32            new ComponentHashmap($components)
33        );
34    }
35}