Lines
100.00%
6 / 6
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Send | 100.00% | 6 / 6 | 100.00% | 3 / 3 | 5 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Client\Script; | |
| 6 | ||
| 7 | use Lorekeeper\Client\Command\Command; | |
| 8 | use Lorekeeper\Server\Event\Event; | |
| 9 | use Lorekeeper\Server\Event\EventBundle; | |
| 10 | use Psl\DateTime\Duration; | |
| 11 | ||
| 12 | final 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 | } |