Lines 86.36% 19 / 22
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 78.57% 11 / 14 0.00% 0 / 1 5.25
 summary 100.00% 1 / 1 100.00% 1 / 1 1
 [Lorekeeper\Server\Event\NamedAfterClass] name 100.00% 6 / 6 100.00% 1 / 1 1
19final readonly class QuestMarkedEvent implements Event
20{
21    use NamedAfterClass;
22
23    public function __construct(
24        public QuestMark $mark,
25    ) {}
26
27    /** @return Option\Option<static> */
28    #[Override]
29    public static function from(Message $message): Option\Option
30    {
31        if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'setAchievement') {
32            return Option\none();
33        }
34
35        try {
36            $achievement = Type\shape([
37                'field' => Type\string(),
38                'index' => Type\uint(),
39                'value' => Type\int(),
40            ], allowUnknownFields: true)->coerce($message->data);
41        } catch (CoercionException $exception) {
42            throw new MalformedEventException(static::class, 'achievement is invalid', $exception);
43        }
44
45        if ($achievement['value'] !== 1) {
46            return Option\none();
47        }
48
49        return QuestMarks::of($achievement['field'], $achievement['index'])->map(
50            static fn(QuestMark $mark): static => new static($mark),
51        );
52    }
53
54    #[Override]
55    public function summary(): string
56    {
57        return "Marked {$this->mark->period->name} quest {$this->mark->group}:{$this->mark->index}";
58    }
59}

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}