Lines
100.00%
5 / 5
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| NoticeEvent | 100.00% | 5 / 5 | 100.00% | 2 / 2 | 2 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| channel | n/a | 0 / 0 | n/a | 0 / 0 | 0 | |||||
| phrase | n/a | 0 / 0 | n/a | 0 / 0 | 0 | |||||
| from | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Server\Event; | |
| 6 | ||
| 7 | use Lorekeeper\Server\Message\Message; | |
| 8 | use Override; | |
| 9 | use Psl\Option; | |
| 10 | ||
| 11 | abstract readonly class NoticeEvent implements Event | |
| 12 | { | |
| 13 | use NamedAfterClass; | |
| 14 | ||
| 15 | final public function __construct() {} | |
| 16 | ||
| 17 | abstract protected static function channel(): string; | |
| 18 | ||
| 19 | abstract protected static function phrase(): string; | |
| 20 | ||
| 21 | /** @return Option\Option<static> */ | |
| 22 | #[Override] | |
| 23 | final public static function from(Message $message): Option\Option | |
| 24 | { | |
| 25 | return Notice::text($message, static::channel())->filter(static fn(string $text): bool => str_contains( | |
| 26 | strtolower($text), | |
| 27 | static::phrase(), | |
| 28 | ))->map(static fn(): static => new static()); | |
| 29 | } | |
| 30 | } |