Passed
Pull Request — main (#526)
by
unknown
15:53 queued 10:20
created

IdentityRestoredEvent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

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