Lines 100.00% 2 / 2
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerSlotCollection 100.00% 2 / 2 100.00% 1 / 1 1 100.00% 1 / 1
 requireSlotById 100.00% 2 / 2 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker\Collection;
6
7use Stewart\Contracts\Collection\ListCollection;
8use Stewart\Runtime\Broker\WorkerSlot;
9use Stewart\Runtime\Exception\WorkerError;
10use Stewart\Runtime\Exception\WorkerException;
11
12/** @extends ListCollection<WorkerSlot> */
13final readonly class WorkerSlotCollection extends ListCollection
14{
15    /** @throws WorkerException */
16    public function requireSlotById(string $workerId): WorkerSlot
17    {
18        return $this->findFirstWhere(static fn(WorkerSlot $slot): bool => (string) $slot->workerId === $workerId)
19            ?? throw WorkerException::createForReason(WorkerError::Unknown, workerId: $workerId);
20    }
21}