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