Completed
Push — develop ( 6a0b2d...4b76b9 )
by
unknown
31s queued 28s
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 8

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\SecondFactorId;
28
use Surfnet\Stepup\Identity\Value\YubikeyPublicId;
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 YubikeyPossessionProvenAndVerifiedEvent 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
     * The Yubikey's public ID.
42
     *
43
     * @var \Surfnet\Stepup\Identity\Value\YubikeyPublicId
44
     */
45
    public $yubikeyPublicId;
46
47
    /**
48
     * @var \Surfnet\Stepup\Identity\Value\CommonName
49
     */
50
    public $commonName;
51
52
    /**
53
     * @var \Surfnet\Stepup\Identity\Value\Email
54
     */
55
    public $email;
56
57
    /**
58
     * @var \Surfnet\Stepup\DateTime\DateTime
59
     */
60
    public $registrationRequestedAt;
61
62
    /**
63
     * @var string
64
     */
65
    public $registrationCode;
66
67
    /**
68
     * @param IdentityId              $identityId
69
     * @param Institution             $institution
70
     * @param SecondFactorId          $secondFactorId
71
     * @param YubikeyPublicId         $yubikeyPublicId
72
     * @param CommonName              $commonName
73
     * @param Email                   $email
74
     * @param DateTime                $registrationRequestedAt
75
     * @param string                  $registrationCode
76
     */
77
    public function __construct(
78
        IdentityId $identityId,
79
        Institution $institution,
80
        SecondFactorId $secondFactorId,
81
        YubikeyPublicId $yubikeyPublicId,
82
        CommonName $commonName,
83
        Email $email,
84
        DateTime $registrationRequestedAt,
85
        $registrationCode
86
    ) {
87
        parent::__construct($identityId, $institution);
88
89
        $this->secondFactorId            = $secondFactorId;
90
        $this->yubikeyPublicId           = $yubikeyPublicId;
91
        $this->commonName                = $commonName;
92
        $this->email                     = $email;
93
        $this->registrationRequestedAt   = $registrationRequestedAt;
94
        $this->registrationCode          = $registrationCode;
95
    }
96
97
    public function getAuditLogMetadata()
98
    {
99
        $metadata                         = new Metadata();
100
        $metadata->identityId             = $this->identityId;
101
        $metadata->identityInstitution    = $this->identityInstitution;
102
        $metadata->secondFactorId         = $this->secondFactorId;
103
        $metadata->secondFactorType       = new SecondFactorType('yubikey');
104
        $metadata->secondFactorIdentifier = $this->yubikeyPublicId;
105
106
        return $metadata;
107
    }
108
109
    public static function deserialize(array $data)
110
    {
111
        return new self(
112
            new IdentityId($data['identity_id']),
113
            new Institution($data['identity_institution']),
114
            new SecondFactorId($data['second_factor_id']),
115
            YubikeyPublicId::unknown(),
116
            CommonName::unknown(),
117
            Email::unknown(),
118
            DateTime::fromString($data['registration_requested_at']),
119
            (string) $data['registration_code']
120
        );
121
    }
122
123
    public function serialize()
124
    {
125
        return [
126
            'identity_id'                 => (string) $this->identityId,
127
            'identity_institution'        => (string) $this->identityInstitution,
128
            'second_factor_id'            => (string) $this->secondFactorId,
129
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
130
            'registration_code'           => $this->registrationCode,
131
        ];
132
    }
133
134
    public function getSensitiveData()
135
    {
136
        return (new SensitiveData)
137
            ->withCommonName($this->commonName)
138
            ->withEmail($this->email)
139
            ->withSecondFactorIdentifier($this->yubikeyPublicId, new SecondFactorType('yubikey'));
140
    }
141
142
    public function setSensitiveData(SensitiveData $sensitiveData)
143
    {
144
        $this->yubikeyPublicId = $sensitiveData->getSecondFactorIdentifier();
145
        $this->email = $sensitiveData->getEmail();
146
        $this->commonName = $sensitiveData->getCommonName();
147
    }
148
}
149