Lines 100.00% 15 / 15
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 buildScheduleStatuses 100.00% 14 / 14 100.00% 1 / 1 4
10final readonly class ScheduleStatusBuilder
11{
12    public function __construct(private WorkerSlotRegistry $slots) {}
13
14    /** @return list<ScheduleStatus> */
15    public function buildScheduleStatuses(): array
16    {
17        $statuses = [];
18
19        foreach ($this->slots->listLiveHandles() as $handle) {
20            foreach ($handle->lastPong->apps ?? [] as $app) {
21                foreach ($app->scheduleReports as $report) {
22                    $statuses[] = new ScheduleStatus(
23                        appId: $app->scope->wireValue(),
24                        workerId: $handle->id->value,
25                        taskId: $report->taskId,
26                        description: $report->description,
27                        nextRunAt: $report->nextRunAt,
28                        lastRunAt: $report->lastRunAt,
29                    );
30                }
31            }
32        }
33
34        usort($statuses, static fn(ScheduleStatus $a, ScheduleStatus $b): int => $a->workerId <=> $b->workerId);
35
36        return $statuses;
37    }
38}