Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
NavigationData
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 make
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
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 ArrayObject;
8use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\NavigationSchema;
9use Hyde\Support\Concerns\Serializable;
10use 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 */
16final 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;
28        $this->priority = $priority;
29        $this->hidden = $hidden;
30        $this->group = $group;
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}