Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
11 / 12
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConsentRecord
91.67% covered (success)
91.67%
11 / 12
66.67% covered (warning)
66.67%
2 / 3
3.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 isGranted
100.00% covered (success)
100.00%
1 / 1
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\Consent\Data;
6
7use App\Support\Row;
8use JsonSerializable;
9
10/**
11 * A single immutable consent ledger row (FSC-87).
12 */
13final class ConsentRecord implements JsonSerializable
14{
15    public int $consentId;
16
17    public int $userId;
18
19    public string $consentType;
20
21    public string $action;
22
23    public string $version;
24
25    public string $languageShown;
26
27    public ?string $ipAddress;
28
29    public ?string $userAgent;
30
31    public string $source;
32
33    public string $createdAt;
34
35    /**
36     * @param array<mixed> $data Repository row, camelCase keys
37     */
38    public function __construct(array $data)
39    {
40        $this->consentId = Row::int($data, 'consentId');
41        $this->userId = Row::int($data, 'userId');
42        $this->consentType = Row::string($data, 'consentType');
43        $this->action = Row::string($data, 'action');
44        $this->version = Row::string($data, 'version');
45        $this->languageShown = Row::string($data, 'languageShown');
46        $this->ipAddress = Row::nullableString($data, 'ipAddress');
47        $this->userAgent = Row::nullableString($data, 'userAgent');
48        $this->source = Row::string($data, 'source');
49        $this->createdAt = Row::string($data, 'createdAt');
50    }
51
52    public function isGranted(): bool
53    {
54        return $this->action === ConsentType::ACTION_GRANTED;
55    }
56
57    /**
58     * @return array<mixed>
59     */
60    public function jsonSerialize(): array
61    {
62        return get_object_vars($this);
63    }
64}