Completed
Push — feature/fix-token-ra-candiate-... ( 2911b4 )
by
unknown
03:26
created

VettedSecondFactor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 108
Duplicated Lines 34.26 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 37
loc 108
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 1
A __construct() 0 3 1
A getId() 0 4 1
A revoke() 12 12 1
A revokeAll() 12 12 1
A complyWithRevocation() 13 13 1
A applyIdentityForgottenEvent() 0 6 1
A getType() 0 4 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 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\Entity;
20
21
use Surfnet\Stepup\Identity\Api\Identity;
22
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
23
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
24
use Surfnet\Stepup\Identity\Event\VettedSecondFactorsAllRevokedEvent;
25
use Surfnet\Stepup\Identity\Event\VettedSecondFactorRevokedEvent;
26
use Surfnet\Stepup\Identity\Value\IdentityId;
27
use Surfnet\Stepup\Identity\Value\SecondFactorId;
28
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier;
29
use Surfnet\StepupBundle\Value\SecondFactorType;
30
31
/**
32
 * A second factor whose possession and its Registrant's identity has been vetted by a Registration Authority.
33
 *
34
 * @SuppressWarnings(PHPMD.UnusedPrivateFields)
35
 */
36
class VettedSecondFactor extends AbstractSecondFactor
37
{
38
    /**
39
     * @var \Surfnet\Stepup\Identity\Api\Identity
40
     */
41
    private $identity;
42
43
    /**
44
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
45
     */
46
    private $id;
47
48
    /**
49
     * @var \Surfnet\StepupBundle\Value\SecondFactorType
50
     */
51
    private $type;
52
53
    /**
54
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier
55
     */
56
    private $secondFactorIdentifier;
57
58
    /**
59
     * @param SecondFactorId $id
60
     * @param Identity $identity
61
     * @param SecondFactorType $type
62
     * @param SecondFactorIdentifier $secondFactorIdentifier
63
     * @return VettedSecondFactor
64
     */
65
    public static function create(
66
        SecondFactorId $id,
67
        Identity $identity,
68
        SecondFactorType $type,
69
        SecondFactorIdentifier $secondFactorIdentifier
70
    ) {
71
        $secondFactor = new self();
72
        $secondFactor->id = $id;
73
        $secondFactor->identity = $identity;
74
        $secondFactor->type = $type;
75
        $secondFactor->secondFactorIdentifier = $secondFactorIdentifier;
76
77
        return $secondFactor;
78
    }
79
80
    final public function __construct()
81
    {
82
    }
83
84
    /**
85
     * @return SecondFactorId
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92 View Code Duplication
    public function revoke()
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...
93
    {
94
        $this->apply(
95
            new VettedSecondFactorRevokedEvent(
96
                $this->identity->getId(),
97
                $this->identity->getInstitution(),
98
                $this->id,
99
                $this->type,
100
                $this->secondFactorIdentifier
101
            )
102
        );
103
    }
104
105 View Code Duplication
    public function revokeAll()
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...
106
    {
107
        $this->apply(
108
            new VettedSecondFactorsAllRevokedEvent(
109
                $this->identity->getId(),
110
                $this->identity->getInstitution(),
111
                $this->id,
112
                $this->type,
113
                $this->secondFactorIdentifier
114
            )
115
        );
116
    }
117
118 View Code Duplication
    public function complyWithRevocation(IdentityId $authorityId)
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...
119
    {
120
        $this->apply(
121
            new CompliedWithVettedSecondFactorRevocationEvent(
122
                $this->identity->getId(),
123
                $this->identity->getInstitution(),
124
                $this->id,
125
                $this->type,
126
                $this->secondFactorIdentifier,
127
                $authorityId
128
            )
129
        );
130
    }
131
132
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
133
    {
134
        $secondFactorIdentifierClass = get_class($this->secondFactorIdentifier);
135
136
        $this->secondFactorIdentifier = $secondFactorIdentifierClass::unknown();
137
    }
138
139
    public function getType()
140
    {
141
        return $this->type;
142
    }
143
}
144