Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.82% covered (warning)
81.82%
9 / 11
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Ref
81.82% covered (warning)
81.82%
9 / 11
50.00% covered (danger)
50.00%
2 / 4
5.15
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 children
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 icon
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
2.01
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Collection;
6
7use Cosray\Exception\RuntimeException;
8use Cosray\NavigationItem;
9use Cosray\NavMeta;
10use Override;
11
12/**
13 * Navigation entry for a collection, resolved from the collection's
14 * schema without instantiating the collection class.
15 */
16final class Ref implements NavigationItem
17{
18    /**
19     * @param class-string $class
20     */
21    public function __construct(
22        public readonly string $class,
23        #[Override]
24        public readonly NavMeta $meta,
25        public readonly string $handle,
26    ) {}
27
28    #[Override]
29    public function slug(): string
30    {
31        return $this->handle;
32    }
33
34    /** @return list<NavigationItem> */
35    #[Override]
36    public function children(): array
37    {
38        return [];
39    }
40
41    /** @param array<array-key, mixed> $args */
42    public function icon(string $id, array $args = []): static
43    {
44        $id = trim($id);
45
46        if ($id === '') {
47            throw new RuntimeException('Collection icon ids must not be empty');
48        }
49
50        $this->meta->icon = [
51            'id' => $id,
52            'args' => $args,
53        ];
54
55        return $this;
56    }
57}