UnverifiedSecondFactorSearchQuery   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setIdentityId() 0 8 1
A setVerificationNonce() 0 8 1
A assertNonEmptyString() 0 10 2
A toHttpQuery() 0 14 3
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 UnverifiedSecondFactorSearchQuery implements HttpQuery
25
{
26
    /**
27
     * @var string
28
     */
29
    private $identityId;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $verificationNonce;
35
36
    /**
37
     * @param string $identityId
38
     * @return self
39
     */
40
    public function setIdentityId($identityId)
41
    {
42
        $this->assertNonEmptyString($identityId, 'identityId');
43
44
        $this->identityId = $identityId;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @param string $verificationNonce
51
     * @return self
52
     */
53
    public function setVerificationNonce($verificationNonce)
54
    {
55
        $this->assertNonEmptyString($verificationNonce, 'verificationNonce');
56
57
        $this->verificationNonce = $verificationNonce;
58
59
        return $this;
60
    }
61
62
    private function assertNonEmptyString($value, $name)
63
    {
64
        $message = sprintf(
65
            '"%s" must be a non-empty string, "%s" given',
66
            $name,
67
            (is_object($value) ? get_class($value) : gettype($value))
68
        );
69
70
        Assert\that($value)->string($message)->notEmpty($message);
71
    }
72
73
    public function toHttpQuery()
74
    {
75
        $fields = [];
76
77
        if ($this->identityId) {
78
            $fields['identityId'] = $this->identityId;
79
        }
80
81
        if ($this->verificationNonce) {
82
            $fields['verificationNonce'] = $this->verificationNonce;
83
        }
84
85
        return '?' . http_build_query($fields);
86
    }
87
}
88