Passed
Push — master ( 888a90...284d56 )
by Caen
13:31 queued 13s
created

DropdownNavItem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 3 1
A getItems() 0 3 1
A searchForDropdownPriorityInNavigationConfig() 0 7 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Navigation;
6
7
use Hyde\Facades\Config;
8
use Illuminate\Support\Collection;
9
10
use 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
 */
17
class 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
    public static function fromArray(string $name, array $items): static
30
    {
31
        return new static($name, $items);
32
    }
33
34
    public function getItems(): Collection
35
    {
36
        return collect($this->items);
0 ignored issues
show
Bug introduced by
$this->items of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        return collect(/** @scrutinizer ignore-type */ $this->items);
Loading history...
37
    }
38
39
    private function searchForDropdownPriorityInNavigationConfig(string $groupKey): ?int
40
    {
41
        return Config::getArray('hyde.navigation.order', [
42
            'index' => 0,
43
            'posts' => 10,
44
            'docs/index' => 100,
45
        ])[$groupKey] ?? null;
46
    }
47
}
48