Completed
Push — feature/refactor-gateway-contr... ( 236313...33303a )
by
unknown
02:26
created

YubikeyOtpVerificationResult   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A didPublicIdMatch() 0 4 2
A didOtpVerificationFail() 0 4 1
A getPublicId() 0 4 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\StepupGateway\GatewayBundle\Service\StepUp;
20
21
use Surfnet\StepupBundle\Value\YubikeyPublicId;
22
23
class YubikeyOtpVerificationResult
24
{
25
    const RESULT_PUBLIC_ID_MATCHED = 0;
26
    const RESULT_PUBLIC_ID_DID_NOT_MATCH = 1;
27
    const RESULT_OTP_VERIFICATION_FAILED = 2;
28
29
    /**
30
     * @var \Surfnet\StepupBundle\Value\YubikeyPublicId|null
31
     */
32
    private $publicId;
33
34
    /**
35
     * @var int One of the RESULT constants.
36
     */
37
    private $result;
38
39
    /**
40
     * @param int $result
41
     * @param YubikeyPublicId|null $publicId
42
     * @throws DomainException When $result is not one of the RESULT constants.
43
     * @throws InvalidArgumentException When the public ID is not a string.
44
     */
45
    public function __construct($result, YubikeyPublicId $publicId = null)
46
    {
47
        $acceptableResults = [
48
            self::RESULT_PUBLIC_ID_MATCHED,
49
            self::RESULT_PUBLIC_ID_DID_NOT_MATCH,
50
            self::RESULT_OTP_VERIFICATION_FAILED
51
        ];
52
53
        if (!in_array($result, $acceptableResults)) {
54
            throw new DomainException('Public ID verification result is not one of the RESULT constants.');
55
        }
56
57
        $this->result = $result;
58
        $this->publicId = $publicId;
59
    }
60
61
    public function didPublicIdMatch()
62
    {
63
        return $this->result === self::RESULT_PUBLIC_ID_MATCHED && $this->publicId !== null;
64
    }
65
66
    public function didOtpVerificationFail()
67
    {
68
        return $this->result === self::RESULT_OTP_VERIFICATION_FAILED;
69
    }
70
71
    /**
72
     * @return YubikeyPublicId|null
73
     */
74
    public function getPublicId()
75
    {
76
        return $this->publicId;
77
    }
78
}
79