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<\Cosray\Collection> $class
20     */
21    public function __construct(
22        public readonly string $class,
23        public readonly NavMeta $meta,
24        public readonly string $handle,
25    ) {}
26
27    #[Override]
28    public function slug(): ?string
29    {
30        return $this->handle;
31    }
32
33    /** @return list<NavigationItem> */
34    #[Override]
35    public function children(): array
36    {
37        return [];
38    }
39
40    /** @param array<array-key, mixed> $args */
41    public function icon(string $id, array $args = []): static
42    {
43        $id = trim($id);
44
45        if ($id === '') {
46            throw new RuntimeException('Collection icon ids must not be empty');
47        }
48
49        $this->meta->icon = [
50            'id' => $id,
51            'args' => $args,
52        ];
53
54        return $this;
55    }
56}