Completed
Push — master ( c960cd...2a99e3 )
by
unknown
01:55
created

RaSecondFactorExportQuery::setOrderBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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
final class RaSecondFactorExportQuery implements HttpQuery
25
{
26
    const STATUS_UNVERIFIED = 'unverified';
27
    const STATUS_VERIFIED = 'verified';
28
    const STATUS_VETTED = 'vetted';
29
    const STATUS_REVOKED = 'revoked';
30
31
    /**
32
     * @var string
33
     */
34
    private $institution;
35
36
    /**
37
     * @var string|null
38
     */
39
    private $name;
40
41
    /**
42
     * @var string|null
43
     */
44
    private $type;
45
46
    /**
47
     * @var string|null The second factor type's ID (eg. Yubikey public ID)
48
     */
49
    private $secondFactorId;
50
51
    /**
52
     * @var string|null
53
     */
54
    private $email;
55
56
    /**
57
     * @var string|null One of the STATUS_* constants.
58
     */
59
    private $status;
60
61
    /**
62
     * @var string|null
63
     */
64
    private $orderBy;
65
66
    /**
67
     * @var string|null
68
     */
69
    private $orderDirection;
70
71
    /**
72
     * @param string $institution
73
     */
74
    public function __construct($institution)
75
    {
76
        $this->assertNonEmptyString($institution, 'institution');
77
        $this->institution = $institution;
78
    }
79
80
    /**
81
     * @return null|string
82
     */
83
    public function getName()
84
    {
85
        return $this->name;
86
    }
87
88
    /**
89
     * @param null|string $name
90
     */
91
    public function setName($name)
92
    {
93
        $this->assertNonEmptyString($name, 'name');
94
95
        $this->name = $name;
96
    }
97
98
    /**
99
     * @return null|string
100
     */
101
    public function getType()
102
    {
103
        return $this->type;
104
    }
105
106
    /**
107
     * @param null|string $type
108
     */
109
    public function setType($type)
110
    {
111
        $this->assertNonEmptyString($type, 'type');
112
113
        $this->type = $type;
114
    }
115
116
    /**
117
     * @return null|string
118
     */
119
    public function getSecondFactorId()
120
    {
121
        return $this->secondFactorId;
122
    }
123
124
    /**
125
     * @param null|string $secondFactorId
126
     */
127
    public function setSecondFactorId($secondFactorId)
128
    {
129
        $this->assertNonEmptyString($secondFactorId, 'secondFactorId');
130
131
        $this->secondFactorId = $secondFactorId;
132
    }
133
134
    /**
135
     * @return null|string
136
     */
137
    public function getEmail()
138
    {
139
        return $this->email;
140
    }
141
142
    /**
143
     * @param null|string $email
144
     */
145
    public function setEmail($email)
146
    {
147
        $this->assertNonEmptyString($email, 'email');
148
149
        $this->email = $email;
150
    }
151
152
    /**
153
     * @return null|string
154
     */
155
    public function getStatus()
156
    {
157
        return $this->status;
158
    }
159
160
    /**
161
     * @param string $status
162
     */
163 View Code Duplication
    public function setStatus($status)
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...
164
    {
165
        Assert\that($status)->choice(
166
            [self::STATUS_UNVERIFIED, self::STATUS_VERIFIED, self::STATUS_VETTED, self::STATUS_REVOKED, ''],
167
            'Invalid second factor status, must be one of the STATUS constants'
168
        );
169
170
        $this->status = $status ?: null;
171
    }
172
173
    /**
174
     * @param string $orderBy
175
     */
176
    public function setOrderBy($orderBy)
177
    {
178
        $this->assertNonEmptyString($orderBy, 'orderBy');
179
180
        $this->orderBy = $orderBy;
181
    }
182
183
    /**
184
     * @param string|null $orderDirection
185
     */
186 View Code Duplication
    public function setOrderDirection($orderDirection)
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...
187
    {
188
        Assert\that($orderDirection)->choice(
189
            ['asc', 'desc', '', null],
190
            "Invalid order direction, must be one of 'asc', 'desc'"
191
        );
192
193
        $this->orderDirection = $orderDirection ?: null;
194
    }
195
196 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...
197
    {
198
        $message = sprintf(
199
            '"%s" must be a non-empty string, "%s" given',
200
            $name,
201
            (is_object($value) ? get_class($value) : gettype($value))
202
        );
203
204
        Assert\that($value)->string($message)->notEmpty($message);
205
    }
206
207
    /**
208
     * Return the Http Query string as should be used, MUST include the '?' prefix.
209
     *
210
     * @return string
211
     */
212 View Code Duplication
    public function toHttpQuery()
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...
213
    {
214
        return '?' . http_build_query(
215
            array_filter(
216
                [
217
                    'institution'    => $this->institution,
218
                    'name'           => $this->name,
219
                    'type'           => $this->type,
220
                    'secondFactorId' => $this->secondFactorId,
221
                    'email'          => $this->email,
222
                    'status'         => $this->status,
223
                    'orderBy'        => $this->orderBy,
224
                    'orderDirection' => $this->orderDirection
225
                ],
226
                function ($value) {
227
                    return !is_null($value);
228
                }
229
            )
230
        );
231
    }
232
}
233