Completed
Push — feature/ra-locations ( 8e7bb5 )
by Boy
12:38
created

VerifiedSecondFactorSearchQuery::toHttpQuery()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 18
rs 9.2
cc 4
eloc 9
nc 8
nop 0
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
    /**
38
     * @var string
39
     */
40
    private $registrationCode;
41
42
    /**
43
     * @param string $identityId
44
     * @return self
45
     */
46
    public function setIdentityId($identityId)
47
    {
48
        $this->assertNonEmptyString($identityId, 'identityId');
49
50
        $this->identityId = $identityId;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param string $secondFactorId
57
     * @return self
58
     */
59
    public function setSecondFactorId($secondFactorId)
60
    {
61
        $this->assertNonEmptyString($secondFactorId, 'secondFactorId');
62
63
        $this->secondFactorId = $secondFactorId;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param string $registrationCode
70
     * @return self
71
     */
72
    public function setRegistrationCode($registrationCode)
73
    {
74
        $this->assertNonEmptyString($registrationCode, 'registrationCode');
75
76
        $this->registrationCode = $registrationCode;
77
78
        return $this;
79
    }
80
81 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...
82
    {
83
        $message = sprintf(
84
            '"%s" must be a non-empty string, "%s" given',
85
            $name,
86
            (is_object($value) ? get_class($value) : gettype($value))
87
        );
88
89
        Assert\that($value)->string($message)->notEmpty($message);
90
    }
91
92
    public function toHttpQuery()
93
    {
94
        $fields = [];
95
96
        if ($this->identityId) {
97
            $fields['identityId'] = $this->identityId;
98
        }
99
100
        if ($this->secondFactorId) {
101
            $fields['secondFactorId'] = $this->secondFactorId;
102
        }
103
104
        if ($this->registrationCode) {
105
            $fields['registrationCode'] = $this->registrationCode;
106
        }
107
108
        return '?' . http_build_query($fields);
109
    }
110
}
111