Lines 100.00% 14 / 14
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% 6 / 6 100.00% 1 / 1 1
 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 QuestTurnInRefusedEvent implements Event
20{
21    use NamedAfterClass;
22
23    public function __construct(
24        public QuestId $quest,
25        public QuestName $name,
26        public string $reason,
27    ) {}
28
29    /** @return Option\Option<static> */
30    #[Override]
31    public static function from(Message $message): Option\Option
32    {
33        return QuestAnswer::read(
34            $message,
35            static::class,
36        )->filter(static fn(QuestAnswer $answer): bool => !$answer->completed)->map(
37            static fn(QuestAnswer $answer): static => new static($answer->quest, $answer->name, $answer->reason),
38        );
39    }
40
41    #[Override]
42    public function summary(): string
43    {
44        return "Could not complete {$this->name->value}: {$this->reason}";
45    }
46}

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}