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

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}