Completed
Push — feature/verify-email-new-prove... ( 7083d2 )
by
unknown
08:05 queued 04:39
created

deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 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\PhoneNumber;
28
use Surfnet\Stepup\Identity\Value\SecondFactorId;
29
use Surfnet\StepupBundle\Value\SecondFactorType;
30
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
32
33 View Code Duplication
class PhonePossessionProvenAndVerifiedEvent 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...
34
{
35
    /**
36
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
37
     */
38
    public $secondFactorId;
39
40
    /**
41
     * @var \Surfnet\Stepup\Identity\Value\PhoneNumber
42
     */
43
    public $phoneNumber;
44
45
    /**
46
     * @var \Surfnet\Stepup\Identity\Value\CommonName
47
     */
48
    public $commonName;
49
50
    /**
51
     * @var \Surfnet\Stepup\Identity\Value\Email
52
     */
53
    public $email;
54
55
    /**
56
     * @var \Surfnet\Stepup\DateTime\DateTime
57
     */
58
    public $registrationRequestedAt;
59
60
    /**
61
     * @var string
62
     */
63
    public $registrationCode;
64
65
    /**
66
     * @param IdentityId $identityId
67
     * @param Institution $identityInstitution
68
     * @param SecondFactorId $secondFactorId
69
     * @param PhoneNumber $phoneNumber
70
     * @param CommonName $commonName
71
     * @param Email $email
72
     * @param DateTime $registrationRequestedAt
73
     * @param string $registrationCode
74
     */
75
    public function __construct(
76
        IdentityId $identityId,
77
        Institution $identityInstitution,
78
        SecondFactorId $secondFactorId,
79
        PhoneNumber $phoneNumber,
80
        CommonName $commonName,
81
        Email $email,
82
        DateTime $registrationRequestedAt,
0 ignored issues
show
Unused Code introduced by
The parameter $registrationRequestedAt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
        $registrationCode
0 ignored issues
show
Unused Code introduced by
The parameter $registrationCode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    ) {
85
        parent::__construct($identityId, $identityInstitution);
86
87
        $this->secondFactorId = $secondFactorId;
88
        $this->phoneNumber = $phoneNumber;
89
        $this->commonName = $commonName;
90
        $this->email = $email;
91
    }
92
93
    public function getAuditLogMetadata()
94
    {
95
        $metadata                         = new Metadata();
96
        $metadata->identityId             = $this->identityId;
97
        $metadata->identityInstitution    = $this->identityInstitution;
98
        $metadata->secondFactorId         = $this->secondFactorId;
99
        $metadata->secondFactorType       = new SecondFactorType('sms');
100
        $metadata->secondFactorIdentifier = $this->phoneNumber;
101
102
        return $metadata;
103
    }
104
105
    public static function deserialize(array $data)
106
    {
107
        return new self(
108
            new IdentityId($data['identity_id']),
109
            new Institution($data['identity_institution']),
110
            new SecondFactorId($data['second_factor_id']),
111
            PhoneNumber::unknown(),
112
            CommonName::unknown(),
113
            Email::unknown(),
114
            DateTime::fromString($data['registration_requested_at']),
115
            (string) $data['registration_code']
116
        );
117
    }
118
119
    public function serialize()
120
    {
121
        return [
122
            'identity_id'               => (string) $this->identityId,
123
            'identity_institution'      => (string) $this->identityInstitution,
124
            'second_factor_id'          => (string) $this->secondFactorId,
125
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
126
            'registration_code'           => $this->registrationCode,
127
        ];
128
    }
129
130
    public function getSensitiveData()
131
    {
132
        return (new SensitiveData)
133
            ->withCommonName($this->commonName)
134
            ->withEmail($this->email)
135
            ->withSecondFactorIdentifier($this->phoneNumber, new SecondFactorType('sms'));
136
    }
137
138
    public function setSensitiveData(SensitiveData $sensitiveData)
139
    {
140
        $this->phoneNumber = $sensitiveData->getSecondFactorIdentifier();
141
        $this->email = $sensitiveData->getEmail();
142
        $this->commonName = $sensitiveData->getCommonName();
143
    }
144
}
145