Completed
Pull Request — feature/test-php-7-2-in-travis (#309)
by
unknown
04:53 queued 02:32
created

serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\CommonName;
23
use Surfnet\Stepup\Identity\Value\DocumentNumber;
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;
28
use Surfnet\Stepup\Identity\Value\NameId;
29
use Surfnet\Stepup\Identity\Value\SecondFactorId;
30
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier;
31
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory;
32
use Surfnet\StepupBundle\Value\SecondFactorType;
33
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
34
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
35
36
/**
37
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
38
 */
39 View Code Duplication
class SecondFactorVettedPossessionSkippedEvent extends IdentityEvent implements Forgettable
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
{
41
    /**
42
     * @var \Surfnet\Stepup\Identity\Value\NameId
43
     */
44
    public $nameId;
45
46
    /**
47
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
48
     */
49
    public $secondFactorId;
50
51
    /**
52
     * @var \Surfnet\StepupBundle\Value\SecondFactorType
53
     */
54
    public $secondFactorType;
55
56
    /**
57
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier
58
     */
59
    public $secondFactorIdentifier;
60
61
    /**
62
     * @var \Surfnet\Stepup\Identity\Value\DocumentNumber
63
     */
64
    public $documentNumber;
65
66
    /**
67
     * @var \Surfnet\Stepup\Identity\Value\CommonName
68
     */
69
    public $commonName;
70
71
    /**
72
     * @var \Surfnet\Stepup\Identity\Value\Email
73
     */
74
    public $email;
75
76
    /**
77
     * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB"
78
     */
79
    public $preferredLocale;
80
81
    /**
82
     * @param IdentityId        $identityId
83
     * @param NameId            $nameId
84
     * @param Institution       $institution
85
     * @param SecondFactorId    $secondFactorId
86
     * @param SecondFactorType  $secondFactorType
87
     * @param SecondFactorIdentifier $secondFactorIdentifier
88
     * @param DocumentNumber    $documentNumber
89
     * @param CommonName        $commonName
90
     * @param Email             $email
91
     * @param Locale            $preferredLocale
92
     *
93
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
94
     */
95
    public function __construct(
96
        IdentityId $identityId,
97
        NameId $nameId,
98
        Institution $institution,
99
        SecondFactorId $secondFactorId,
100
        SecondFactorType $secondFactorType,
101
        SecondFactorIdentifier $secondFactorIdentifier,
102
        DocumentNumber $documentNumber,
103
        CommonName $commonName,
104
        Email $email,
105
        Locale $preferredLocale
106
    ) {
107
        parent::__construct($identityId, $institution);
108
109
        $this->nameId                 = $nameId;
110
        $this->secondFactorId         = $secondFactorId;
111
        $this->secondFactorType       = $secondFactorType;
112
        $this->secondFactorIdentifier = $secondFactorIdentifier;
113
        $this->documentNumber         = $documentNumber;
114
        $this->commonName             = $commonName;
115
        $this->email                  = $email;
116
        $this->preferredLocale        = $preferredLocale;
117
    }
118
119
    public function getAuditLogMetadata()
120
    {
121
        $metadata                         = new Metadata();
122
        $metadata->identityId             = $this->identityId;
123
        $metadata->identityInstitution    = $this->identityInstitution;
124
        $metadata->secondFactorId         = $this->secondFactorId;
125
        $metadata->secondFactorType       = $this->secondFactorType;
126
        $metadata->secondFactorIdentifier = $this->secondFactorIdentifier;
127
128
        return $metadata;
129
    }
130
131
    public static function deserialize(array $data)
132
    {
133
        $secondFactorType = new SecondFactorType($data['second_factor_type']);
134
135
        return new self(
136
            new IdentityId($data['identity_id']),
137
            new NameId($data['name_id']),
138
            new Institution($data['identity_institution']),
139
            new SecondFactorId($data['second_factor_id']),
140
            $secondFactorType,
141
            SecondFactorIdentifierFactory::unknownForType($secondFactorType),
142
            DocumentNumber::unknown(),
143
            CommonName::unknown(),
144
            Email::unknown(),
145
            new Locale($data['preferred_locale'])
146
        );
147
    }
148
149
    public function serialize(): array
150
    {
151
        return [
152
            'identity_id'              => (string) $this->identityId,
153
            'name_id'                  => (string) $this->nameId,
154
            'identity_institution'     => (string) $this->identityInstitution,
155
            'second_factor_id'         => (string) $this->secondFactorId,
156
            'second_factor_type'       => (string) $this->secondFactorType,
157
            'preferred_locale'         => (string) $this->preferredLocale,
158
        ];
159
    }
160
161
    public function getSensitiveData()
162
    {
163
        return (new SensitiveData)
164
            ->withCommonName($this->commonName)
165
            ->withEmail($this->email)
166
            ->withSecondFactorIdentifier($this->secondFactorIdentifier, $this->secondFactorType)
167
            ->withDocumentNumber($this->documentNumber);
168
    }
169
170
    public function setSensitiveData(SensitiveData $sensitiveData)
171
    {
172
        $this->email          = $sensitiveData->getEmail();
173
        $this->commonName     = $sensitiveData->getCommonName();
174
        $this->secondFactorIdentifier = $sensitiveData->getSecondFactorIdentifier();
175
        $this->documentNumber = $sensitiveData->getDocumentNumber();
176
    }
177
}
178