Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationPreference
87.50% covered (warning)
87.50%
7 / 8
50.00% covered (danger)
50.00%
1 / 2
2.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Notification\Data;
6
7use App\Support\Row;
8use JsonSerializable;
9
10/**
11 * A single notification preference row — one type/channel toggle for one user.
12 */
13final class NotificationPreference implements JsonSerializable
14{
15    public int $preferenceId;
16
17    public int $userId;
18
19    public string $notificationType;
20
21    public string $channel;
22
23    public bool $enabled;
24
25    public string $createdAt;
26
27    public string $updatedAt;
28
29    /**
30     * @param array<mixed> $data Repository row, camelCase keys
31     */
32    public function __construct(array $data)
33    {
34        $this->preferenceId = Row::int($data, 'preferenceId');
35        $this->userId = Row::int($data, 'userId');
36        $this->notificationType = Row::string($data, 'notificationType');
37        $this->channel = Row::string($data, 'channel');
38        $this->enabled = Row::bool($data, 'enabled');
39        $this->createdAt = Row::string($data, 'createdAt');
40        $this->updatedAt = Row::string($data, 'updatedAt');
41    }
42
43    /**
44     * @return array<mixed>
45     */
46    public function jsonSerialize(): array
47    {
48        return get_object_vars($this);
49    }
50}