Lines
100.00%
11 / 11
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getPlatform | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| getTriggerId | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | ||
| getTriggerData | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| withFiredAt | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 10 | final readonly class TriggerEvent | |
| 11 | { | |
| 12 | /** @param array<string, mixed> $trigger */ | |
| 13 | public function __construct( | |
| 14 | public array $trigger, | |
| 15 | public ?EventContext $context = null, | |
| 16 | public ?Instant $firedAt = null, | |
| 17 | ) {} | |
| 18 | ||
| 19 | public function getPlatform(): ?string | |
| 20 | { | |
| 21 | $platform = $this->trigger['platform'] ?? $this->trigger['trigger'] ?? null; | |
| 22 | ||
| 23 | return \is_string($platform) ? $platform : null; | |
| 24 | } | |
| 25 | ||
| 26 | public function getTriggerId(): ?string | |
| 27 | { | |
| 28 | $id = $this->trigger['id'] ?? null; | |
| 29 | ||
| 30 | if (\is_string($id)) { | |
| 31 | return $id; | |
| 32 | } | |
| 33 | ||
| 34 | $index = $this->trigger['idx'] ?? null; | |
| 35 | ||
| 36 | return \is_string($index) || \is_int($index) ? (string) $index : null; | |
| 37 | } | |
| 38 | ||
| 39 | /** @return array<string, mixed> */ | |
| 40 | public function getTriggerData(): array | |
| 41 | { | |
| 42 | return $this->trigger; | |
| 43 | } | |
| 44 | ||
| 45 | public function getValue(string $key): mixed | |
| 46 | { | |
| 47 | return $this->trigger[$key] ?? null; | |
| 48 | } | |
| 49 | ||
| 50 | public function withFiredAt(Instant $firedAt): self | |
| 51 | { | |
| 52 | return new self($this->trigger, $this->context, $firedAt); | |
| 53 | } | |
| 54 | } |