Completed
Push — develop ( 4b76b9...136345 )
by
unknown
07:15 queued 01:31
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * Copyright 2018 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;
28
use Surfnet\Stepup\Identity\Value\U2fKeyHandle;
29
use Surfnet\Stepup\Identity\Value\SecondFactorId;
30
use Surfnet\StepupBundle\Value\SecondFactorType;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
33
34 View Code Duplication
class U2fDevicePossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable, PossessionProvenAndVerified
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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
35
{
36
    /**
37
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
38
     */
39
    public $secondFactorId;
40
41
    /**
42
     * @var \Surfnet\Stepup\Identity\Value\U2fKeyHandle
43
     */
44
    public $keyHandle;
45
46
    /**
47
     * @var \Surfnet\Stepup\Identity\Value\CommonName
48
     */
49
    public $commonName;
50
51
    /**
52
     * @var \Surfnet\Stepup\Identity\Value\Email
53
     */
54
    public $email;
55
56
    /**
57
     * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB"
58
     */
59
    public $preferredLocale;
60
61
    /**
62
     * @var \Surfnet\Stepup\DateTime\DateTime
63
     */
64
    public $registrationRequestedAt;
65
66
    /**
67
     * @var string
68
     */
69
    public $registrationCode;
70
71
    /**
72
     * @param IdentityId $identityId
73
     * @param Institution $identityInstitution
74
     * @param SecondFactorId $secondFactorId
75
     * @param U2fKeyHandle $keyHandle
76
     * @param CommonName $commonName
77
     * @param Email $email
78
     * @param Locale $locale
79
     * @param DateTime $registrationRequestedAt
80
     * @param string $registrationCode
81
     */
82
    public function __construct(
83
        IdentityId $identityId,
84
        Institution $identityInstitution,
85
        SecondFactorId $secondFactorId,
86
        U2fKeyHandle $keyHandle,
87
        CommonName $commonName,
88
        Email $email,
89
        Locale $locale,
90
        DateTime $registrationRequestedAt,
91
        $registrationCode
92
    ) {
93
        parent::__construct($identityId, $identityInstitution);
94
95
        $this->secondFactorId = $secondFactorId;
96
        $this->keyHandle = $keyHandle;
97
        $this->commonName = $commonName;
98
        $this->email = $email;
99
        $this->preferredLocale = $locale;
100
        $this->registrationRequestedAt = $registrationRequestedAt;
101
        $this->registrationCode = $registrationCode;
102
    }
103
104
    public function getAuditLogMetadata()
105
    {
106
        $metadata                         = new Metadata();
107
        $metadata->identityId             = $this->identityId;
108
        $metadata->identityInstitution    = $this->identityInstitution;
109
        $metadata->secondFactorId         = $this->secondFactorId;
110
        $metadata->secondFactorType       = new SecondFactorType('sms');
111
        $metadata->secondFactorIdentifier = $this->keyHandle;
112
113
        return $metadata;
114
    }
115
116
    public static function deserialize(array $data)
117
    {
118
        // BC compatibility for event replay in test-environment only (2.8.0, fixed in 2.8.1)
119
        if (!isset($data['preferred_locale'])) {
120
            $data['preferred_locale'] = 'en_GB';
121
        }
122
123
        return new self(
124
            new IdentityId($data['identity_id']),
125
            new Institution($data['identity_institution']),
126
            new SecondFactorId($data['second_factor_id']),
127
            U2fKeyHandle::unknown(),
128
            CommonName::unknown(),
129
            Email::unknown(),
130
            new Locale($data['preferred_locale']),
131
            DateTime::fromString($data['registration_requested_at']),
132
            (string) $data['registration_code']
133
        );
134
    }
135
136
    public function serialize()
137
    {
138
        return [
139
            'identity_id'                 => (string) $this->identityId,
140
            'identity_institution'        => (string) $this->identityInstitution,
141
            'second_factor_id'            => (string) $this->secondFactorId,
142
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
143
            'registration_code'           => $this->registrationCode,
144
            'preferred_locale'            => (string) $this->preferredLocale,
145
        ];
146
    }
147
148
    public function getSensitiveData()
149
    {
150
        return (new SensitiveData)
151
            ->withCommonName($this->commonName)
152
            ->withEmail($this->email)
153
            ->withSecondFactorIdentifier($this->keyHandle, new SecondFactorType('u2f'));
154
    }
155
156
    public function setSensitiveData(SensitiveData $sensitiveData)
157
    {
158
        $this->keyHandle   = $sensitiveData->getSecondFactorIdentifier();
159
        $this->email       = $sensitiveData->getEmail();
160
        $this->commonName  = $sensitiveData->getCommonName();
161
    }
162
}
163