Completed
Pull Request — develop (#76)
by
unknown
02:00 queued 15s
created

RaSecondFactorExportQuery::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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
     * @var string
79
     */
80
    private $actorId;
81
82
    /**
83
     * @param string $actorInstitution
84
     * @param string $actorId
85
     */
86
    public function __construct($actorInstitution, $actorId)
87
    {
88
        $this->assertNonEmptyString($actorInstitution, 'institution');
89
        $this->actorInstitution = $actorInstitution;
90
        $this->actorId = $actorId;
91
    }
92
93
    /**
94
     * @param string $actorInstitution
0 ignored issues
show
Bug introduced by
There is no parameter named $actorInstitution. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
95
     * @return VerifiedSecondFactorSearchQuery
0 ignored issues
show
Documentation introduced by
Should the return type not be RaSecondFactorExportQuery?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

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