Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MenuItem
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
18 / 18
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        int $counterInMenu = 0,
18    ) {
19        $components = [];
20        $submenuCounter = 0;
21        foreach ($menuItem->children as $path => $child) {
22            $components[] = new MenuItem($child, [...$currentPath, $path], $index + 1, $submenuCounter);
23            $submenuCounter++;
24        }
25        parent::__construct(
26            [
27                'index' => $index,
28                'id' => $menuItem->id,
29                'name' => $menuItem->name,
30                'route' => $menuItem->route,
31                'icon' => $menuItem->icon,
32                'allowed' => $menuItem->allowed,
33                'counterInMenu' => $counterInMenu,
34                'subcomponents' => array_keys($components),
35            ],
36            new ComponentHashmap($components)
37        );
38    }
39}