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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
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 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\GssfId;
26
use Surfnet\Stepup\Identity\Value\IdentityId;
27
use Surfnet\Stepup\Identity\Value\Institution;
28
use Surfnet\Stepup\Identity\Value\SecondFactorId;
29
use Surfnet\Stepup\Identity\Value\StepupProvider;
30
use Surfnet\StepupBundle\Value\SecondFactorType;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
33
34
class GssfPossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable
35
{
36
    /**
37
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
38
     */
39
    public $secondFactorId;
40
41
    /**
42
     * @var \Surfnet\Stepup\Identity\Value\StepupProvider
43
     */
44
    public $stepupProvider;
45
46
    /**
47
     * @var \Surfnet\Stepup\Identity\Value\GssfId
48
     */
49
    public $gssfId;
50
51
    /**
52
     * @var \Surfnet\Stepup\Identity\Value\CommonName
53
     */
54
    public $commonName;
55
56
    /**
57
     * @var \Surfnet\Stepup\Identity\Value\Email
58
     */
59
    public $email;
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 StepupProvider          $stepupProvider
76
     * @param GssfId                  $gssfId
77
     * @param CommonName              $commonName
78
     * @param Email                   $email
79
     * @param DateTime                $registrationRequestedAt
80
     * @param string                  $registrationCode
81
     */
82
    public function __construct(
83
        IdentityId $identityId,
84
        Institution $identityInstitution,
85
        SecondFactorId $secondFactorId,
86
        StepupProvider $stepupProvider,
87
        GssfId $gssfId,
88
        CommonName $commonName,
89
        Email $email,
90
        DateTime $registrationRequestedAt,
91
        $registrationCode
92
    ) {
93
        parent::__construct($identityId, $identityInstitution);
94
95
        $this->secondFactorId            = $secondFactorId;
96
        $this->stepupProvider            = $stepupProvider;
97
        $this->gssfId                    = $gssfId;
98
        $this->commonName                = $commonName;
99
        $this->email                     = $email;
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((string) $this->stepupProvider);
111
        $metadata->secondFactorIdentifier = $this->gssfId;
112
113
        return $metadata;
114
    }
115
116 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...
117
    {
118
        return new self(
119
            new IdentityId($data['identity_id']),
120
            new Institution($data['identity_institution']),
121
            new SecondFactorId($data['second_factor_id']),
122
            new StepupProvider($data['stepup_provider']),
123
            GssfId::unknown(),
124
            CommonName::unknown(),
125
            Email::unknown(),
126
            DateTime::fromString($data['registration_requested_at']),
127
            (string) $data['registration_code']
128
        );
129
    }
130
131
    public function serialize()
132
    {
133
        return [
134
            'identity_id'                 => (string) $this->identityId,
135
            'identity_institution'        => (string) $this->identityInstitution,
136
            'second_factor_id'            => (string) $this->secondFactorId,
137
            'stepup_provider'             => (string) $this->stepupProvider,
138
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
139
            'registration_code'           => $this->registrationCode,
140
        ];
141
    }
142
143 View Code Duplication
    public function getSensitiveData()
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...
144
    {
145
        return (new SensitiveData)
146
            ->withCommonName($this->commonName)
147
            ->withEmail($this->email)
148
            ->withSecondFactorIdentifier($this->gssfId, new SecondFactorType((string) $this->stepupProvider));
149
    }
150
151
    public function setSensitiveData(SensitiveData $sensitiveData)
152
    {
153
        $this->gssfId = $sensitiveData->getSecondFactorIdentifier();
154
        $this->email = $sensitiveData->getEmail();
155
        $this->commonName = $sensitiveData->getCommonName();
156
    }
157
}
158