Completed
Push — feature/verify-email-proven-ev... ( 178167 )
by
unknown
04:44
created

ImplicitlyVerifiedByIdp::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
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 Broadway\Serializer\SerializableInterface;
22
use Surfnet\Stepup\DateTime\DateTime;
23
use Surfnet\Stepup\Identity\Value\IdentityId;
24
use Surfnet\Stepup\Identity\Value\Institution;
25
use Surfnet\Stepup\Identity\Value\SecondFactorId;
26
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier;
27
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory;
28
use Surfnet\StepupBundle\Value\SecondFactorType;
29
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
30
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
31
32
class ImplicitlyVerifiedByIdp implements Forgettable, SerializableInterface
33
{
34
    /**
35
     * @var IdentityId
36
     */
37
    public $identityId;
38
39
    /**
40
     * @var Institution
41
     */
42
    public $identityInstitution;
43
44
    /**
45
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
46
     */
47
    public $secondFactorId;
48
49
    /**
50
     * @var \Surfnet\StepupBundle\Value\SecondFactorType
51
     */
52
    public $secondFactorType;
53
54
    /**
55
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier
56
     */
57
    public $secondFactorIdentifier;
58
59
    /**
60
     * @var \Surfnet\Stepup\DateTime\DateTime
61
     */
62
    public $registrationRequestedAt;
63
64
    /**
65
     * @var string
66
     */
67
    public $registrationCode;
68
69
    /**
70
     * @param IdentityId        $identityId
71
     * @param Institution       $identityInstitution
72
     * @param SecondFactorId    $secondFactorId
73
     * @param SecondFactorType  $secondFactorType
74
     * @param SecondFactorIdentifier $secondFactorIdentifier
75
     * @param DateTime          $registrationRequestedAt
76
     * @param string            $registrationCode
77
     *
78
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
79
     */
80
    public function __construct(
81
        IdentityId $identityId,
82
        Institution $identityInstitution,
83
        SecondFactorId $secondFactorId,
84
        SecondFactorType $secondFactorType,
85
        SecondFactorIdentifier $secondFactorIdentifier,
86
        DateTime $registrationRequestedAt,
87
        $registrationCode
88
    ) {
89
        $this->identityId = $identityId;
90
        $this->identityInstitution = $identityInstitution;
91
        $this->secondFactorId          = $secondFactorId;
92
        $this->secondFactorType        = $secondFactorType;
93
        $this->secondFactorIdentifier  = $secondFactorIdentifier;
94
        $this->registrationRequestedAt = $registrationRequestedAt;
95
        $this->registrationCode        = $registrationCode;
96
    }
97
98 View Code Duplication
    public static function deserialize(array $data)
0 ignored issues
show
Duplication introduced by
This method 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...
99
    {
100
        $secondFactorType = new SecondFactorType($data['second_factor_type']);
101
102
        return new self(
103
            new IdentityId($data['identity_id']),
104
            new Institution($data['identity_institution']),
105
            new SecondFactorId($data['second_factor_id']),
106
            $secondFactorType,
107
            SecondFactorIdentifierFactory::unknownForType($secondFactorType),
108
            DateTime::fromString($data['registration_requested_at']),
109
            $data['registration_code']
110
        );
111
    }
112
113
    public function serialize()
114
    {
115
        return [
116
            'identity_id'               => (string) $this->identityId,
117
            'identity_institution'      => (string) $this->identityInstitution,
118
            'second_factor_id'          => (string) $this->secondFactorId,
119
            'second_factor_type'        => (string) $this->secondFactorType,
120
            'registration_requested_at' => (string) $this->registrationRequestedAt,
121
            'registration_code'         => $this->registrationCode,
122
        ];
123
    }
124
125
    public function getSensitiveData()
126
    {
127
        return (new SensitiveData)
128
            ->withSecondFactorIdentifier($this->secondFactorIdentifier, $this->secondFactorType);
129
    }
130
131
    public function setSensitiveData(SensitiveData $sensitiveData)
132
    {
133
        $this->secondFactorIdentifier = $sensitiveData->getSecondFactorIdentifier();
134
    }
135
}
136