Completed
Push — master ( 5467e4...183ea4 )
by Boy
05:06 queued 01:02
created

VettedSecondFactor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 25
loc 95
wmc 7
lcom 1
cbo 4
rs 10

7 Methods

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