Completed
Push — feature/fga-vetting-procedure ( 602b7b )
by Michiel
01:30
created

VerifiedSecondFactorSearchQuery   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 105
loc 105
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setIdentityId() 8 8 1
A setSecondFactorId() 8 8 1
A setRegistrationCode() 8 8 1
A setInstitution() 8 8 1
A assertNonEmptyString() 10 10 2
A toHttpQuery() 20 20 4

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\StepupMiddlewareClient\Identity\Dto;
20
21
use Assert;
22
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery;
23
24 View Code Duplication
class VerifiedSecondFactorSearchQuery implements HttpQuery
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...
25
{
26
    /**
27
     * @var string
28
     */
29
    private $identityId;
30
31
    /**
32
     * @var string
33
     */
34
    private $secondFactorId;
35
36
    /**
37
     * @var string
38
     */
39
    private $registrationCode;
40
41
    /**
42
     * @var string
43
     */
44
    private $institution;
45
46
    /**
47
     * @param string $identityId
48
     * @return self
49
     */
50
    public function setIdentityId($identityId)
51
    {
52
        $this->assertNonEmptyString($identityId, 'identityId');
53
54
        $this->identityId = $identityId;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @param string $secondFactorId
61
     * @return self
62
     */
63
    public function setSecondFactorId($secondFactorId)
64
    {
65
        $this->assertNonEmptyString($secondFactorId, 'secondFactorId');
66
67
        $this->secondFactorId = $secondFactorId;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @param string $registrationCode
74
     * @return self
75
     */
76
    public function setRegistrationCode($registrationCode)
77
    {
78
        $this->assertNonEmptyString($registrationCode, 'registrationCode');
79
80
        $this->registrationCode = $registrationCode;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @param string $institution
87
     */
88
    public function setInstitution($institution)
89
    {
90
        $this->assertNonEmptyString($institution, 'institution');
91
92
        $this->institution = $institution;
93
94
        return $this;
95
    }
96
97
    private function assertNonEmptyString($value, $name)
98
    {
99
        $message = sprintf(
100
            '"%s" must be a non-empty string, "%s" given',
101
            $name,
102
            (is_object($value) ? get_class($value) : gettype($value))
103
        );
104
105
        Assert\that($value)->string($message)->notEmpty($message);
106
    }
107
108
    public function toHttpQuery()
109
    {
110
        $fields = [];
111
112
        $fields['institution'] = $this->institution;
113
114
        if ($this->identityId) {
115
            $fields['identityId'] = $this->identityId;
116
        }
117
118
        if ($this->secondFactorId) {
119
            $fields['secondFactorId'] = $this->secondFactorId;
120
        }
121
122
        if ($this->registrationCode) {
123
            $fields['registrationCode'] = $this->registrationCode;
124
        }
125
126
        return '?' . http_build_query($fields);
127
    }
128
}
129