Passed
Pull Request — main (#526)
by
unknown
11:52 queued 05:50
created

IdentityRestoredEvent::setSensitiveData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Surfnet\Stepup\Identity\Event;
4
5
use Surfnet\Stepup\Identity\AuditLog\Metadata;
6
use Surfnet\Stepup\Identity\Value\CommonName;
7
use Surfnet\Stepup\Identity\Value\Email;
8
use Surfnet\Stepup\Identity\Value\IdentityId;
9
use Surfnet\Stepup\Identity\Value\Institution;
10
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
11
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
12
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
13
14
class IdentityRestoredEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class IdentityRestoredEvent
Loading history...
15
{
16
17
    /**
18
     * @var string[]
19
     */
20
    private array $allowlist = [
21
        'id',
22
        'common_name',
23
        'email',
24
        'institution',
25
    ];
26
27
    public function __construct(
28
        private readonly IdentityId $id,
29
        private readonly Institution $institution,
30
        public CommonName $commonName,
31
        public Email $email,
32
    ) {
33
        parent::__construct($id, $institution);
34
    }
35
36
    public function getAuditLogMetadata(): Metadata
37
    {
38
        $metadata = new Metadata();
39
        $metadata->identityId = $this->id;
40
        $metadata->identityInstitution = $this->institution;
41
42
        return $metadata;
43
    }
44
45
    /**
46
     * @param array<string,string> $data
47
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
48
    public static function deserialize(array $data): self
49
    {
50
        return new self(
51
            new IdentityId($data['id']),
52
            new Institution($data['institution']),
53
            new CommonName($data['common_name']),
54
            new Email($data['email']),
55
        );
56
    }
57
58
    /**
59
     * @return array<string,string>
60
     */
61
    public function serialize(): array
62
    {
63
        return [
64
            'id' => (string)$this->id,
65
            'institution' => (string)$this->institution,
66
            'common_name' => (string)$this->commonName,
67
            'email' => (string)$this->email,
68
        ];
69
    }
70
71
    public function getSensitiveData(): SensitiveData
72
    {
73
        return (new SensitiveData)
74
            ->withCommonName($this->commonName)
75
            ->withEmail($this->email);
76
    }
77
78
    public function setSensitiveData(SensitiveData $sensitiveData): void
79
    {
80
        $this->commonName = $sensitiveData->getCommonName();
81
        $this->email = $sensitiveData->getEmail();
82
    }
83
84
    /**
85
     * @return array<string,string>
86
     */
87
    public function obtainUserData(): array
88
    {
89
        $serializedPublicUserData = $this->serialize();
90
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
91
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
92
    }
93
94
    /**
95
     * @return string[]
96
     */
97
    public function getAllowlist(): array
98
    {
99
        return $this->allowlist;
100
    }
101
}
102