NavigationData   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A toArray() 0 7 1
A make() 0 3 1
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