Completed
Push — feature/fga-vet-and-manage ( 3b3e62...4376a5 )
by Michiel
10:21
created

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