Completed
Push — master ( d2aa7f...78f4d4 )
by Michiel
03:30 queued 02:21
created

RaSecondFactorExportQuery::setInstitution()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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 DateTime;
23
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery;
24
25
final class RaSecondFactorExportQuery implements HttpQuery
26
{
27
    const STATUS_UNVERIFIED = 'unverified';
28
    const STATUS_VERIFIED = 'verified';
29
    const STATUS_VETTED = 'vetted';
30
    const STATUS_REVOKED = 'revoked';
31
32
    /**
33
     * @var string
34
     */
35
    private $actorInstitution;
36
37
    /**
38
     * @var string|null
39
     */
40
    private $name;
41
42
    /**
43
     * @var string|null
44
     */
45
    private $type;
46
47
    /**
48
     * @var string|null The second factor type's ID (eg. Yubikey public ID)
49
     */
50
    private $secondFactorId;
51
52
    /**
53
     * @var string|null
54
     */
55
    private $email;
56
57
    /**
58
     * @var string|null
59
     */
60
    private $institution;
61
62
    /**
63
     * @var string|null One of the STATUS_* constants.
64
     */
65
    private $status;
66
67
    /**
68
     * @var string|null
69
     */
70
    private $orderBy;
71
72
    /**
73
     * @var string|null
74
     */
75
    private $orderDirection;
76
77
    /**
78
     * @param string $actorInstitution
79
     */
80
    public function __construct($actorInstitution)
81
    {
82
        $this->assertNonEmptyString($actorInstitution, 'institution');
83
        $this->actorInstitution = $actorInstitution;
84
    }
85
86
    public function getFileName()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
87
    {
88
        $date = new DateTime();
89
        $date = $date->format('Y-m-d');
90
91
        $fileName = "token_export_{$date}";
92
93
        if ($this->type) {
94
            $fileName .= "-{$this->type}";
95
        }
96
97
        if ($this->status) {
98
            $fileName .= "-{$this->status}";
99
        }
100
101
        return $fileName;
102
    }
103
104
    /**
105
     * @return null|string
106
     */
107
    public function getName()
108
    {
109
        return $this->name;
110
    }
111
112
    /**
113
     * @param null|string $name
114
     */
115
    public function setName($name)
116
    {
117
        $this->assertNonEmptyString($name, 'name');
118
119
        $this->name = $name;
120
    }
121
122
    /**
123
     * @return null|string
124
     */
125
    public function getType()
126
    {
127
        return $this->type;
128
    }
129
130
    /**
131
     * @param null|string $type
132
     */
133
    public function setType($type)
134
    {
135
        $this->assertNonEmptyString($type, 'type');
136
137
        $this->type = $type;
138
    }
139
140
    /**
141
     * @return null|string
142
     */
143
    public function getSecondFactorId()
144
    {
145
        return $this->secondFactorId;
146
    }
147
148
    /**
149
     * @param null|string $secondFactorId
150
     */
151
    public function setSecondFactorId($secondFactorId)
152
    {
153
        $this->assertNonEmptyString($secondFactorId, 'secondFactorId');
154
155
        $this->secondFactorId = $secondFactorId;
156
    }
157
158
    /**
159
     * @return null|string
160
     */
161
    public function getEmail()
162
    {
163
        return $this->email;
164
    }
165
166
    /**
167
     * @param null|string $email
168
     */
169
    public function setEmail($email)
170
    {
171
        $this->assertNonEmptyString($email, 'email');
172
173
        $this->email = $email;
174
    }
175
176
    /**
177
     * @return null|string
178
     */
179
    public function getInstitution()
180
    {
181
        return $this->institution;
182
    }
183
184
    /**
185
     * @param null|string $institution
186
     */
187
    public function setInstitution($institution)
188
    {
189
        $this->institution = $institution;
190
    }
191
192
    /**
193
     * @return null|string
194
     */
195
    public function getStatus()
196
    {
197
        return $this->status;
198
    }
199
200
    /**
201
     * @param string $status
202
     */
203 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...
204
    {
205
        Assert\that($status)->choice(
206
            [self::STATUS_UNVERIFIED, self::STATUS_VERIFIED, self::STATUS_VETTED, self::STATUS_REVOKED, ''],
207
            'Invalid second factor status, must be one of the STATUS constants'
208
        );
209
210
        $this->status = $status ?: null;
211
    }
212
213
    /**
214
     * @param string $orderBy
215
     */
216
    public function setOrderBy($orderBy)
217
    {
218
        $this->assertNonEmptyString($orderBy, 'orderBy');
219
220
        $this->orderBy = $orderBy;
221
    }
222
223
    /**
224
     * @param string|null $orderDirection
225
     */
226 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...
227
    {
228
        Assert\that($orderDirection)->choice(
229
            ['asc', 'desc', '', null],
230
            "Invalid order direction, must be one of 'asc', 'desc'"
231
        );
232
233
        $this->orderDirection = $orderDirection ?: null;
234
    }
235
236 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...
237
    {
238
        $message = sprintf(
239
            '"%s" must be a non-empty string, "%s" given',
240
            $name,
241
            (is_object($value) ? get_class($value) : gettype($value))
242
        );
243
244
        Assert\that($value)->string($message)->notEmpty($message);
245
    }
246
247
    /**
248
     * Return the Http Query string as should be used, MUST include the '?' prefix.
249
     *
250
     * @return string
251
     */
252 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...
253
    {
254
        return '?' . http_build_query(
255
            array_filter(
256
                [
257
                    'actorInstitution' => $this->actorInstitution,
258
                    'name'             => $this->name,
259
                    'type'             => $this->type,
260
                    'secondFactorId'   => $this->secondFactorId,
261
                    'email'            => $this->email,
262
                    'institution'      => $this->institution,
263
                    'status'           => $this->status,
264
                    'orderBy'          => $this->orderBy,
265
                    'orderDirection'   => $this->orderDirection
266
                ],
267
                function ($value) {
268
                    return !is_null($value);
269
                }
270
            )
271
        );
272
    }
273
}
274