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

IdentityRestoredEvent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
dl 0
loc 70
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowlist() 0 3 1
A getAuditLogMetadata() 0 7 1
A getSensitiveData() 0 5 1
A serialize() 0 7 1
A obtainUserData() 0 5 1
A __construct() 0 7 1
A deserialize() 0 7 1
A setSensitiveData() 0 4 1
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
    private array $allowlist = [
17
        'id',
18
        'common_name',
19
        'email',
20
        'institution',
21
    ];
22
23
    public function __construct(
24
        private readonly IdentityId $id,
25
        private readonly Institution $institution,
26
        public CommonName $commonName,
27
        public Email $email,
28
    ) {
29
        parent::__construct($id, $institution);
30
    }
31
32
    public function getAuditLogMetadata(): Metadata
33
    {
34
        $metadata = new Metadata();
35
        $metadata->identityId = $this->id;
36
        $metadata->identityInstitution = $this->institution;
37
38
        return $metadata;
39
    }
40
41
    public static function deserialize(array $data): self
42
    {
43
        return new self(
44
            new IdentityId($data['id']),
45
            new Institution($data['institution']),
46
            new CommonName($data['common_name']),
47
            new Email($data['email']),
48
        );
49
    }
50
51
    public function serialize(): array
52
    {
53
        return [
54
            'id' => (string)$this->id,
55
            'institution' => (string)$this->institution,
56
            'common_name' => (string)$this->commonName,
57
            'email' => (string)$this->email,
58
        ];
59
    }
60
61
    public function getSensitiveData(): SensitiveData
62
    {
63
        return (new SensitiveData)
64
            ->withCommonName($this->commonName)
65
            ->withEmail($this->email);
66
    }
67
68
    public function setSensitiveData(SensitiveData $sensitiveData): void
69
    {
70
        $this->commonName = $sensitiveData->getCommonName();
71
        $this->email = $sensitiveData->getEmail();
72
    }
73
74
    public function obtainUserData(): array
75
    {
76
        $serializedPublicUserData = $this->serialize();
77
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
78
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
79
    }
80
81
    public function getAllowlist(): array
82
    {
83
        return $this->allowlist;
84
    }
85
}
86