Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
DropdownNavItem
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 fromArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getItems
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 searchForDropdownPriorityInNavigationConfig
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Hyde\Framework\Features\Navigation;
6
7use Hyde\Facades\Config;
8use Illuminate\Support\Collection;
9
10use function collect;
11
12/**
13 * A navigation item that contains other navigation items.
14 *
15 * Unlike a regular navigation items, a dropdown item does not have a route or URL destination.
16 */
17class DropdownNavItem extends NavItem
18{
19    /** @var array<NavItem> */
20    public array $items;
21
22    /** @param array<NavItem> $items */
23    public function __construct(string $label, array $items, ?int $priority = null)
24    {
25        parent::__construct('', $label, $priority ?? $this->searchForDropdownPriorityInNavigationConfig($label) ?? 999);
26        $this->items = $items;
27    }
28
29    /** @param array<NavItem> $items */
30    public static function fromArray(string $name, array $items): static
31    {
32        return new static($name, $items);
33    }
34
35    /** @return Collection<NavItem> */
36    public function getItems(): Collection
37    {
38        return collect($this->items);
39    }
40
41    private function searchForDropdownPriorityInNavigationConfig(string $groupKey): ?int
42    {
43        /** @var array<string, int> $config */
44        $config = Config::getArray('hyde.navigation.order', [
45            'index' => 0,
46            'posts' => 10,
47            'docs/index' => 100,
48        ]);
49
50        return $config[$groupKey] ?? null;
51    }
52}