NavigationData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Navigation;
6
7
use ArrayObject;
8
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\NavigationSchema;
9
use Hyde\Support\Concerns\Serializable;
10
use Hyde\Support\Contracts\SerializableContract;
11
12
/**
13
 * Object implementation for the NavigationSchema. It extends the ArrayObject class so
14
 * that its data can be accessed using dot notation in the page's front matter data.
15
 */
16
final class NavigationData extends ArrayObject implements NavigationSchema, SerializableContract
17
{
18
    use Serializable;
19
20
    public readonly string $label;
21
    public readonly int $priority;
22
    public readonly bool $hidden;
23
    public readonly ?string $group;
24
25
    public function __construct(string $label, int $priority, bool $hidden, ?string $group = null)
26
    {
27
        $this->label = $label;
0 ignored issues
show
Bug introduced by
The property label is declared read-only in Hyde\Framework\Features\Navigation\NavigationData.
Loading history...
28
        $this->priority = $priority;
0 ignored issues
show
Bug introduced by
The property priority is declared read-only in Hyde\Framework\Features\Navigation\NavigationData.
Loading history...
29
        $this->hidden = $hidden;
0 ignored issues
show
Bug introduced by
The property hidden is declared read-only in Hyde\Framework\Features\Navigation\NavigationData.
Loading history...
30
        $this->group = $group;
0 ignored issues
show
Bug introduced by
The property group is declared read-only in Hyde\Framework\Features\Navigation\NavigationData.
Loading history...
31
32
        parent::__construct($this->toArray());
33
    }
34
35
    /** @param  array{label: string, priority: int, hidden: bool, group: string|null}  $data */
36
    public static function make(array $data): self
37
    {
38
        return new self(...$data);
39
    }
40
41
    /** @return array{label: string,  priority: int, hidden: bool, group: string|null} */
42
    public function toArray(): array
43
    {
44
        return [
45
            'label' => $this->label,
46
            'priority' => $this->priority,
47
            'hidden' => $this->hidden,
48
            'group' => $this->group,
49
        ];
50
    }
51
}
52