EmailVerifiedEvent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A deserialize() 0 15 1
A getAllowlist() 0 3 1
A getAuditLogMetadata() 0 10 1
A getSensitiveData() 0 6 1
A obtainUserData() 0 5 1
A setSensitiveData() 0 5 1
A __construct() 0 13 1
A serialize() 0 10 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\DateTime\DateTime;
22
use Surfnet\Stepup\Identity\AuditLog\Metadata;
23
use Surfnet\Stepup\Identity\Value\CommonName;
24
use Surfnet\Stepup\Identity\Value\Email;
25
use Surfnet\Stepup\Identity\Value\IdentityId;
26
use Surfnet\Stepup\Identity\Value\Institution;
27
use Surfnet\Stepup\Identity\Value\Locale;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Identity\Value\Locale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Surfnet\Stepup\Identity\Value\SecondFactorId;
29
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier;
30
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory;
31
use Surfnet\StepupBundle\Value\SecondFactorType;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
33
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
34
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
35
36
class EmailVerifiedEvent extends IdentityEvent implements
37
    Forgettable,
38
    PossessionProvenAndVerified,
39
    RightToObtainDataInterface
40
{
41
    /**
42
     * @var string[]
43
     */
44
    private array $allowlist = [
45
        'identity_id',
46
        'identity_institution',
47
        'second_factor_id',
48
        'second_factor_type',
49
        'second_factor_identifier',
50
        'registration_requested_at',
51
        'preferred_locale',
52
        'common_name',
53
        'email',
54
    ];
55
56
    /**
57
     * @param IdentityId $identityId
58
     * @param Institution $identityInstitution
59
     * @param SecondFactorId $secondFactorId
60
     * @param SecondFactorType $secondFactorType
61
     * @param SecondFactorIdentifier $secondFactorIdentifier
62
     * @param DateTime $registrationRequestedAt
63
     * @param string $registrationCode
64
     * @param CommonName $commonName
65
     * @param Email $email
66
     * @param Locale $preferredLocale
67
     *
68
     * @SuppressWarnings("PHPMD.ExcessiveParameterList")
69
     */
70
    public function __construct(
71
        IdentityId                     $identityId,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$identityId"; 21 found
Loading history...
72
        Institution                    $identityInstitution,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$identityInstitution"; 20 found
Loading history...
73
        public SecondFactorId                 $secondFactorId,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$secondFactorId"; 17 found
Loading history...
74
        public SecondFactorType               $secondFactorType,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$secondFactorType"; 15 found
Loading history...
75
        private SecondFactorIdentifier $secondFactorIdentifier,
76
        public DateTime                       $registrationRequestedAt,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$registrationRequestedAt"; 23 found
Loading history...
77
        public string                  $registrationCode,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$registrationCode"; 18 found
Loading history...
78
        public CommonName                     $commonName,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$commonName"; 21 found
Loading history...
79
        public Email                          $email,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$email"; 26 found
Loading history...
80
        public Locale                         $preferredLocale,
0 ignored issues
show
Coding Style introduced by
Expected 1 space between type hint and argument "$preferredLocale"; 25 found
Loading history...
81
    ) {
82
        parent::__construct($identityId, $identityInstitution);
83
    }
84
85
    public function getAuditLogMetadata(): Metadata
86
    {
87
        $metadata = new Metadata();
88
        $metadata->identityId = $this->identityId;
89
        $metadata->identityInstitution = $this->identityInstitution;
90
        $metadata->secondFactorId = $this->secondFactorId;
91
        $metadata->secondFactorType = $this->secondFactorType;
92
        $metadata->secondFactorIdentifier = $this->secondFactorIdentifier;
93
94
        return $metadata;
95
    }
96
97
    public static function deserialize(array $data): self
98
    {
99
        $secondFactorType = new SecondFactorType($data['second_factor_type']);
100
101
        return new self(
102
            new IdentityId($data['identity_id']),
103
            new Institution($data['identity_institution']),
104
            new SecondFactorId($data['second_factor_id']),
105
            $secondFactorType,
106
            SecondFactorIdentifierFactory::unknownForType($secondFactorType),
107
            DateTime::fromString($data['registration_requested_at']),
108
            $data['registration_code'],
109
            CommonName::unknown(),
110
            Email::unknown(),
111
            new Locale($data['preferred_locale']),
112
        );
113
    }
114
115
    /**
116
     * The data ending up in the event_stream, be careful not to include sensitive data here!
117
     *
118
     * @return array<string, mixed>
119
     */
120
    public function serialize(): array
121
    {
122
        return [
123
            'identity_id' => (string)$this->identityId,
124
            'identity_institution' => (string)$this->identityInstitution,
125
            'second_factor_id' => (string)$this->secondFactorId,
126
            'second_factor_type' => (string)$this->secondFactorType,
127
            'registration_requested_at' => (string)$this->registrationRequestedAt,
128
            'registration_code' => $this->registrationCode,
129
            'preferred_locale' => (string)$this->preferredLocale,
130
        ];
131
    }
132
133
    public function getSensitiveData(): SensitiveData
134
    {
135
        return (new SensitiveData)
0 ignored issues
show
Coding Style introduced by
Parentheses must be used when instantiating a new class
Loading history...
136
            ->withCommonName($this->commonName)
137
            ->withEmail($this->email)
138
            ->withSecondFactorIdentifier($this->secondFactorIdentifier, $this->secondFactorType);
139
    }
140
141
    public function setSensitiveData(SensitiveData $sensitiveData): void
142
    {
143
        $this->email = $sensitiveData->getEmail();
144
        $this->commonName = $sensitiveData->getCommonName();
145
        $this->secondFactorIdentifier = $sensitiveData->getSecondFactorIdentifier();
146
    }
147
148
    public function obtainUserData(): array
149
    {
150
        $serializedPublicUserData = $this->serialize();
151
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
152
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
153
    }
154
155
    /**
156
     * @return string[]
157
     */
158
    public function getAllowlist(): array
159
    {
160
        return $this->allowlist;
161
    }
162
}
163