IdentityEmailChangedEvent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A deserialize() 0 6 1
A getAuditLogMetadata() 0 7 1
A getSensitiveData() 0 4 1
A getAllowlist() 0 3 1
A serialize() 0 5 1
A setSensitiveData() 0 3 1
A __construct() 0 3 1
A obtainUserData() 0 5 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\Stepup\Identity\Event;
20
21
use Surfnet\Stepup\Identity\AuditLog\Metadata;
22
use Surfnet\Stepup\Identity\Value\Email;
23
use Surfnet\Stepup\Identity\Value\IdentityId;
24
use Surfnet\Stepup\Identity\Value\Institution;
25
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
26
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
27
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
28
29
class IdentityEmailChangedEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface
30
{
31
    /**
32
     * @var string[]
33
     */
34
    private array $allowlist = [
35
        'id',
36
        'identity_institution',
37
        'email',
38
    ];
39
40
    public function __construct(IdentityId $identityId, Institution $institution, public Email $email)
41
    {
42
        parent::__construct($identityId, $institution);
43
    }
44
45
    public function getAuditLogMetadata(): Metadata
46
    {
47
        $metadata = new Metadata();
48
        $metadata->identityId = $this->identityId;
49
        $metadata->identityInstitution = $this->identityInstitution;
50
51
        return $metadata;
52
    }
53
54
    /**
55
     * @param array $data
56
     * @return IdentityEmailChangedEvent
57
     */
58
    public static function deserialize(array $data): self
59
    {
60
        return new self(
61
            new IdentityId($data['id']),
62
            new Institution($data['institution']),
63
            Email::unknown(),
64
        );
65
    }
66
67
    /**
68
     * The data ending up in the event_stream, be careful not to include sensitive data here!
69
     *
70
     * @return array<string, mixed>
71
     */
72
    public function serialize(): array
73
    {
74
        return [
75
            'id' => (string)$this->identityId,
76
            'institution' => (string)$this->identityInstitution,
77
        ];
78
    }
79
80
    public function getSensitiveData(): SensitiveData
81
    {
82
        return (new SensitiveData)
0 ignored issues
show
Coding Style introduced by
Parentheses must be used when instantiating a new class
Loading history...
83
            ->withEmail($this->email);
84
    }
85
86
    public function setSensitiveData(SensitiveData $sensitiveData): void
87
    {
88
        $this->email = $sensitiveData->getEmail();
89
    }
90
91
    public function obtainUserData(): array
92
    {
93
        $serializedPublicUserData = $this->serialize();
94
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
95
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
96
    }
97
98
    /**
99
     * @return string[]
100
     */
101
    public function getAllowlist(): array
102
    {
103
        return $this->allowlist;
104
    }
105
}
106