Lines 100.00% 2 / 2
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
LabelCollection 100.00% 2 / 2 100.00% 2 / 2 2 100.00% 1 / 1
 keyedByLabelId 100.00% 1 / 1 100.00% 1 / 1 1
 find 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Registry\Collection;
6
7use Stewart\Contracts\Collection\KeyedCollection;
8use Stewart\Contracts\Registry\Label;
9use Stewart\Contracts\Registry\LabelId;
10
11/** @extends KeyedCollection<string, Label> */
12final readonly class LabelCollection extends KeyedCollection
13{
14    /** @param iterable<Label> $entries */
15    public static function keyedByLabelId(iterable $entries): self
16    {
17        return self::keyedBy($entries, static fn(Label $entry): string => $entry->labelId->value);
18    }
19
20    public function find(LabelId $labelId): ?Label
21    {
22        return $this->elementAt($labelId->value);
23    }
24}