Passed
Push — master ( a77e6b...67a175 )
by Caen
13:07 queued 12s
created

DropdownNavItem::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Navigation;
6
7
use Illuminate\Support\Collection;
8
9
/**
10
 * A navigation item that contains other navigation items.
11
 *
12
 * Unlike a regular navigation items, a dropdown item does not have a route or URL destination.
13
 *
14
 * @see \Hyde\Framework\Testing\Unit\DropdownNavItemTest
15
 */
16
class DropdownNavItem extends NavItem
17
{
18
    /** @var array<NavItem> */
19
    public array $items;
20
    public string $name;
21
    public string $href = '';
22
23
    /** @param array<NavItem> $items */
24
    public function __construct(string $name, array $items)
25
    {
26
        parent::__construct('', $name, 999);
27
        $this->items = $items;
28
        $this->name = $name;
29
    }
30
31
    public static function fromArray(string $name, array $items): static
32
    {
33
        return new static($name, $items);
34
    }
35
36
    public function getItems(): Collection
37
    {
38
        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

38
        return collect(/** @scrutinizer ignore-type */ $this->items);
Loading history...
39
    }
40
}
41