Completed
Push — master ( ed3593...2f770f )
by Boy
9s
created

VerifiedSecondFactorSearchQuery   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 11.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 9
c 4
b 0
f 1
lcom 1
cbo 1
dl 10
loc 86
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setIdentityId() 0 8 1
A setSecondFactorId() 0 8 1
A setRegistrationCode() 0 8 1
A assertNonEmptyString() 10 10 2
A toHttpQuery() 0 18 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
class VerifiedSecondFactorSearchQuery implements HttpQuery
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
     * @param string $identityId
43
     * @return self
44
     */
45
    public function setIdentityId($identityId)
46
    {
47
        $this->assertNonEmptyString($identityId, 'identityId');
48
49
        $this->identityId = $identityId;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param string $secondFactorId
56
     * @return self
57
     */
58
    public function setSecondFactorId($secondFactorId)
59
    {
60
        $this->assertNonEmptyString($secondFactorId, 'secondFactorId');
61
62
        $this->secondFactorId = $secondFactorId;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $registrationCode
69
     * @return self
70
     */
71
    public function setRegistrationCode($registrationCode)
72
    {
73
        $this->assertNonEmptyString($registrationCode, 'registrationCode');
74
75
        $this->registrationCode = $registrationCode;
76
77
        return $this;
78
    }
79
80 View Code Duplication
    private function assertNonEmptyString($value, $name)
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...
81
    {
82
        $message = sprintf(
83
            '"%s" must be a non-empty string, "%s" given',
84
            $name,
85
            (is_object($value) ? get_class($value) : gettype($value))
86
        );
87
88
        Assert\that($value)->string($message)->notEmpty($message);
89
    }
90
91
    public function toHttpQuery()
92
    {
93
        $fields = [];
94
95
        if ($this->identityId) {
96
            $fields['identityId'] = $this->identityId;
97
        }
98
99
        if ($this->secondFactorId) {
100
            $fields['secondFactorId'] = $this->secondFactorId;
101
        }
102
103
        if ($this->registrationCode) {
104
            $fields['registrationCode'] = $this->registrationCode;
105
        }
106
107
        return '?' . http_build_query($fields);
108
    }
109
}
110