Lines
0.00%
0 / 3
Functions and Methods
0.00%
0 / 3
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| EntityRegistryCollection | 0.00% | 0 / 3 | 0.00% | 0 / 3 | 12 | 0.00% | 0 / 1 | |||
| keyedByEntityId | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| find | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| toRegisteredEntities | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Client\Registry\Collection; | |
| 6 | ||
| 7 | use Stewart\Client\Registry\EntityRegistryEntry; | |
| 8 | use Stewart\Contracts\Collection\KeyedCollection; | |
| 9 | use Stewart\Contracts\Entity\EntityId; | |
| 10 | use Stewart\Contracts\Registry\Collection\RegisteredEntityCollection; | |
| 11 | use Stewart\Contracts\Registry\RegisteredEntity; | |
| 12 | ||
| 13 | /** @extends KeyedCollection<string, EntityRegistryEntry> */ | |
| 14 | final readonly class EntityRegistryCollection extends KeyedCollection | |
| 15 | { | |
| 16 | /** @param iterable<EntityRegistryEntry> $entries */ | |
| 17 | public static function keyedByEntityId(iterable $entries): self | |
| 18 | { | |
| 19 | return self::keyedBy($entries, static fn(EntityRegistryEntry $entry): string => $entry->entityId->value); | |
| 20 | } | |
| 21 | ||
| 22 | public function find(EntityId $entityId): ?EntityRegistryEntry | |
| 23 | { | |
| 24 | return $this->elementAt($entityId->value); | |
| 25 | } | |
| 26 | ||
| 27 | public function toRegisteredEntities(): RegisteredEntityCollection | |
| 28 | { | |
| 29 | return RegisteredEntityCollection::keyedByEntityId($this->mapToList(static fn(EntityRegistryEntry $entry): RegisteredEntity => $entry->toRegisteredEntity())); | |
| 30 | } | |
| 31 | } |