Lines 90.90% 10 / 11
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 unknown 0.00% 0 / 1 0.00% 0 / 1 2
 fromArray 100.00% 8 / 8 100.00% 1 / 1 4
 isSameOrParentOf 100.00% 1 / 1 100.00% 1 / 1 3
7final readonly class EventContext
8{
9    public function __construct(
10        public string $id,
11        public ?string $parentId = null,
12        public ?string $userId = null,
13    ) {}
14
15    public static function unknown(): self
16    {
17        return new self('');
18    }
19
20    /** @param array<array-key, mixed> $raw */
21    public static function fromArray(array $raw): self
22    {
23        $id = $raw['id'] ?? '';
24        $parentId = $raw['parent_id'] ?? null;
25        $userId = $raw['user_id'] ?? null;
26
27        return new self(
28            id: \is_string($id) ? $id : '',
29            parentId: \is_string($parentId) ? $parentId : null,
30            userId: \is_string($userId) ? $userId : null,
31        );
32    }
33
34    public function isSameOrParentOf(self $other): bool
35    {
36        return $this->id !== '' && ($other->id === $this->id || $other->parentId === $this->id);
37    }
38}