Completed
Pull Request — feature/fine-grained-authoriza... (#246)
by
unknown
56:03 queued 45:22
created

RegistrationAuthorityRetractedForInstitutionEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 8
dl 82
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 1
A getAuditLogMetadata() 8 8 1
A deserialize() 11 11 1
A serialize() 9 9 1
A getSensitiveData() 6 6 1
A setSensitiveData() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Identity\AuditLog\Metadata;
22
use Surfnet\Stepup\Identity\Value\CommonName;
23
use Surfnet\Stepup\Identity\Value\Email;
24
use Surfnet\Stepup\Identity\Value\IdentityId;
25
use Surfnet\Stepup\Identity\Value\Institution;
26
use Surfnet\Stepup\Identity\Value\NameId;
27
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
28
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
29
30 View Code Duplication
class RegistrationAuthorityRetractedForInstitutionEvent 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...
31
{
32
    /**
33
     * @var NameId
34
     */
35
    public $nameId;
36
37
    /**
38
     * @var CommonName
39
     */
40
    public $commonName;
41
42
    /**
43
     * @var Email
44
     */
45
    public $email;
46
47
    /**
48
     * @var Institution
49
     */
50
    public $raInstitution;
51
52
    public function __construct(
53
        IdentityId $identityId,
54
        Institution $institution,
55
        NameId $nameId,
56
        CommonName $commonName,
57
        Email $email,
58
        Institution $raInstitution
59
    ) {
60
        parent::__construct($identityId, $institution);
61
62
        $this->nameId     = $nameId;
63
        $this->commonName = $commonName;
64
        $this->email      = $email;
65
        $this->raInstitution = $raInstitution;
66
    }
67
68
    public function getAuditLogMetadata()
69
    {
70
        $metadata                         = new Metadata();
71
        $metadata->identityId             = $this->identityId;
72
        $metadata->identityInstitution    = $this->identityInstitution;
73
74
        return $metadata;
75
    }
76
77
    public static function deserialize(array $data)
78
    {
79
        return new self(
80
            new IdentityId($data['identity_id']),
81
            new Institution($data['identity_institution']),
82
            new NameId($data['name_id']),
83
            CommonName::unknown(),
84
            Email::unknown(),
85
            new Institution($data['ra_institution'])
86
        );
87
    }
88
89
    public function serialize()
90
    {
91
        return [
92
            'identity_id'          => (string) $this->identityId,
93
            'identity_institution' => (string) $this->identityInstitution,
94
            'name_id'              => (string) $this->nameId,
95
            'ra_institution'       => (string) $this->raInstitution,
96
        ];
97
    }
98
99
    public function getSensitiveData()
100
    {
101
        return (new SensitiveData)
102
            ->withCommonName($this->commonName)
103
            ->withEmail($this->email);
104
    }
105
106
    public function setSensitiveData(SensitiveData $sensitiveData)
107
    {
108
        $this->email      = $sensitiveData->getEmail();
109
        $this->commonName = $sensitiveData->getCommonName();
110
    }
111
}
112