Lines
93.75%
15 / 16
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| from | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 5 | ||
| summary | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| [Lorekeeper\Server\Event\NamedAfterClass] name | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | ||
| 18 | final readonly class LoginSucceededEvent implements Event | |
| 19 | { | |
| 20 | use NamedAfterClass; | |
| 21 | ||
| 22 | public function __construct( | |
| 23 | public SocketId $socketId, | |
| 24 | ) {} | |
| 25 | ||
| 26 | /** @return Option\Option<static> */ | |
| 27 | #[Override] | |
| 28 | public static function from(Message $message): Option\Option | |
| 29 | { | |
| 30 | if (!$message instanceof DelimitedMessage || ($message->data[1] ?? null) !== 'loginResponse') { | |
| 31 | return Option\none(); | |
| 32 | } | |
| 33 | ||
| 34 | if (($message->data[3] ?? null) !== 'true') { | |
| 35 | return Option\none(); | |
| 36 | } | |
| 37 | ||
| 38 | try { | |
| 39 | $socketId = Type\positive_int()->coerce($message->data[4] ?? null); | |
| 40 | } catch (CoercionException $exception) { | |
| 41 | throw new MalformedEventException(static::class, 'socket id is missing or invalid', $exception); | |
| 42 | } | |
| 43 | ||
| 44 | return Option\some(new static(new SocketId($socketId))); | |
| 45 | } | |
| 46 | ||
| 47 | #[Override] | |
| 48 | public function summary(): string | |
| 49 | { | |
| 50 | return "Logged in as socket {$this->socketId->value}"; | |
| 51 | } | |
| 52 | } |
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 | } |