Completed
Push — feature/mock-yubikey-service ( d86ac2 )
by
unknown
02:40
created

YubikeyOtpVerificationResult   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

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\ApiBundle\Dto;
20
21
use DomainException;
22
use Surfnet\StepupBundle\Value\YubikeyPublicId;
23
24
class YubikeyOtpVerificationResult
25
{
26
    const RESULT_PUBLIC_ID_MATCHED = 0;
27
    const RESULT_PUBLIC_ID_DID_NOT_MATCH = 1;
28
    const RESULT_OTP_VERIFICATION_FAILED = 2;
29
30
    /**
31
     * @var \Surfnet\StepupBundle\Value\YubikeyPublicId|null
32
     */
33
    private $publicId;
34
35
    /**
36
     * @var int One of the RESULT constants.
37
     */
38
    private $result;
39
40
    /**
41
     * @param int $result
42
     * @param YubikeyPublicId|null $publicId
43
     * @throws DomainException When $result is not one of the RESULT constants.
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