Lines 100.00% 17 / 17
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% 9 / 9 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
22final readonly class ItemEquippedEvent implements Event
23{
24    use NamedAfterClass;
25
26    public function __construct(
27        public PlayerSpawnId $player,
28        public ItemId $itemId,
29    ) {}
30
31    /** @return Option\Option<static> */
32    #[Override]
33    public static function from(Message $message): Option\Option
34    {
35        if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'equipItem') {
36            return Option\none();
37        }
38
39        try {
40            $data = Type\shape([
41                'uid' => Type\positive_int(),
42                'ItemID' => Type\positive_int(),
43            ], allowUnknownFields: true)->coerce($message->data);
44        } catch (CoercionException $exception) {
45            throw new MalformedEventException(static::class, 'equipped item is missing or invalid', $exception);
46        }
47
48        return Option\some(new static(new PlayerSpawnId($data['uid']), new ItemId($data['ItemID'])));
49    }
50
51    #[Override]
52    public function summary(): string
53    {
54        return "Spawn {$this->player->value} equipped item {$this->itemId->value}";
55    }
56}

From Lorekeeper\Server\Event\NamedAfterClass

7trait 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}