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
RegisteredEntityCollection 100.00% 2 / 2 100.00% 2 / 2 2 100.00% 1 / 1
 keyedByEntityId 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\Entity\EntityId;
9use Stewart\Contracts\Registry\RegisteredEntity;
10
11/** @extends KeyedCollection<string, RegisteredEntity> */
12final readonly class RegisteredEntityCollection extends KeyedCollection
13{
14    /** @param iterable<RegisteredEntity> $entries */
15    public static function keyedByEntityId(iterable $entries): self
16    {
17        return self::keyedBy($entries, static fn(RegisteredEntity $entry): string => $entry->entityId->value);
18    }
19
20    public function find(EntityId $entityId): ?RegisteredEntity
21    {
22        return $this->elementAt($entityId->value);
23    }
24}