Lines 100.00% 6 / 6
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 awaits 100.00% 4 / 4 100.00% 1 / 1 2
 concrete 100.00% 1 / 1 100.00% 1 / 1 2
12final readonly class Send implements Instruction
13{
14    public function __construct(
15        public Command $command,
16        public ?Await $await = null,
17    ) {}
18
19    /**
20     * @param class-string<Event>|class-string<EventBundle> $event
21     * @param class-string<Event>|class-string<EventBundle> ...$more
22     */
23    public function awaits(Duration $within, string $event, string ...$more): self
24    {
25        $events = self::concrete($event);
26        foreach ($more as $awaited) {
27            $events = [...$events, ...self::concrete($awaited)];
28        }
29
30        return new self($this->command, new Await(array_values(array_unique($events)), $within));
31    }
32
33    /**
34     * @param class-string<Event>|class-string<EventBundle> $awaited
35     *
36     * @return non-empty-list<class-string<Event>>
37     */
38    private static function concrete(string $awaited): array
39    {
40        return is_subclass_of($awaited, EventBundle::class) ? $awaited::events() : [$awaited];
41    }
42}