OtpVerificationResult::isSuccessful()   A
last analyzed

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
namespace Surfnet\YubikeyApiClient\Service;
4
5
class OtpVerificationResult
6
{
7
    /** The OTP is valid. */
8
    const STATUS_OK = 'OK';
9
    /** The OTP is invalid format. */
10
    const ERROR_BAD_OTP = 'BAD_OTP';
11
    /** The OTP has already been seen by the service. */
12
    const ERROR_REPLAYED_OTP = 'REPLAYED_OTP';
13
    /** The HMAC signature verification failed. */
14
    const ERROR_BAD_SIGNATURE = 'BAD_SIGNATURE';
15
    /** The request lacks a parameter. */
16
    const ERROR_MISSING_PARAMETER = 'MISSING_PARAMETER';
17
    /** The request id does not exist. */
18
    const ERROR_NO_SUCH_CLIENT = 'NO_SUCH_CLIENT';
19
    /** The request id is not allowed to verify OTPs. */
20
    const ERROR_OPERATION_NOT_ALLOWED = 'OPERATION_NOT_ALLOWED';
21
    /** Unexpected error in our server. Please contact us if you see this error. */
22
    const ERROR_BACKEND_ERROR = 'BACKEND_ERROR';
23
    /** Server could not get requested number of syncs during before timeout */
24
    const ERROR_NOT_ENOUGH_ANSWERS = 'NOT_ENOUGH_ANSWERS';
25
    /** Server has seen the OTP/Nonce combination before */
26
    const ERROR_REPLAYED_REQUEST = 'REPLAYED_REQUEST';
27
28
    /**
29
     * @var string $status
30
     */
31
    private $status;
32
33
    /**
34
     * @param string $status
35
     */
36
    public function __construct($status)
37
    {
38
        $this->status = $status;
39
    }
40
41
    /**
42
     * @return boolean
43
     */
44
    public function isSuccessful()
45
    {
46
        return $this->status === self::STATUS_OK;
47
    }
48
49
    /**
50
     * @return string|null NULL if verification was successful, or one of the ERROR_* constants.
51
     */
52
    public function getError()
53
    {
54
        return $this->isSuccessful() ? null : $this->status;
55
    }
56
}
57