Lines
100.00%
19 / 19
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| from | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 4 | ||
| summary | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Server\Event\NamedAfterClass] name | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | ||
| 22 | final readonly class PlayerLeftEvent implements Event | |
| 23 | { | |
| 24 | use NamedAfterClass; | |
| 25 | ||
| 26 | public function __construct( | |
| 27 | public PlayerSpawnId $spawnId, | |
| 28 | public PlayerName $name, | |
| 29 | ) {} | |
| 30 | ||
| 31 | /** @return Option\Option<static> */ | |
| 32 | #[Override] | |
| 33 | public static function from(Message $message): Option\Option | |
| 34 | { | |
| 35 | if (!$message instanceof DelimitedMessage || ($message->data[1] ?? null) !== 'exitArea') { | |
| 36 | return Option\none(); | |
| 37 | } | |
| 38 | ||
| 39 | try { | |
| 40 | $spawnId = Type\positive_int()->coerce($message->data[3] ?? null); | |
| 41 | $name = Type\non_empty_string()->coerce($message->data[4] ?? null); | |
| 42 | } catch (CoercionException $exception) { | |
| 43 | throw new MalformedEventException( | |
| 44 | static::class, | |
| 45 | 'player spawn id or name is missing or invalid', | |
| 46 | $exception, | |
| 47 | ); | |
| 48 | } | |
| 49 | ||
| 50 | return Option\some(new static(new PlayerSpawnId($spawnId), new PlayerName($name))); | |
| 51 | } | |
| 52 | ||
| 53 | #[Override] | |
| 54 | public function summary(): string | |
| 55 | { | |
| 56 | return "{$this->name->value} (spawn {$this->spawnId->value}) left"; | |
| 57 | } | |
| 58 | } |
From Lorekeeper\Server\Event\NamedAfterClass
| 7 | trait NamedAfterClass | |
| 8 | { | |
| 9 | public function name(): string | |
| 10 | { | |
| 11 | $class = static::class; | |
| 12 | ||
| 13 | return (string) preg_replace( | |
| 14 | '/Event$/', | |
| 15 | replacement: '', | |
| 16 | subject: substr($class, (int) strrpos($class, needle: '\\') + 1), | |
| 17 | ); | |
| 18 | } | |
| 19 | } |