ProofOfPossessionResult   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 15

12 Methods

Rating   Name   Duplication   Size   Complexity  
A wereTooManyAttemptsMade() 0 3 1
A secondFactorCreated() 0 7 2
A tooManyAttempts() 0 3 1
A proofOfPossessionCommandFailed() 0 3 1
A isSuccessful() 0 3 2
A wasIncorrectChallengeResponseGiven() 0 3 1
A didProofOfPossessionFail() 0 3 2
A hasChallengeExpired() 0 3 1
A getSecondFactorId() 0 3 1
A incorrectChallenge() 0 3 1
A __construct() 0 2 1
A challengeExpired() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2014 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SmsSecondFactor;
22
23
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\InvalidArgumentException;
24
25
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
 * @SuppressWarnings(PHPMD.TooManyMethods)
27
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
28
final class ProofOfPossessionResult
29
{
30
    public const STATUS_CHALLENGE_OK = 0;
31
    public const STATUS_INCORRECT_CHALLENGE = 1;
32
    public const STATUS_CHALLENGE_EXPIRED = 2;
33
    public const STATUS_TOO_MANY_ATTEMPTS = 3;
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @param int $status One of
0 ignored issues
show
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter name; 1 found
Loading history...
37
     * @param string|null $secondFactorId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
38
     */
39
    private function __construct(private $status, private $secondFactorId = null)
40
    {
41
    }
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @return ProofOfPossessionResult
45
     */
46
    public static function challengeExpired(): self
47
    {
48
        return new self(self::STATUS_CHALLENGE_EXPIRED);
49
    }
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @return ProofOfPossessionResult
53
     */
54
    public static function incorrectChallenge(): self
55
    {
56
        return new self(self::STATUS_INCORRECT_CHALLENGE);
57
    }
58
59
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @return ProofOfPossessionResult
61
     */
62
    public static function proofOfPossessionCommandFailed(): self
63
    {
64
        return new self(self::STATUS_CHALLENGE_OK);
65
    }
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @param string $secondFactorId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
69
     * @return ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
70
     */
71
    public static function secondFactorCreated($secondFactorId): self
72
    {
73
        if (!is_string($secondFactorId)) {
0 ignored issues
show
introduced by
The condition is_string($secondFactorId) is always true.
Loading history...
74
            throw InvalidArgumentException::invalidType('string', 'secondFactorId', $secondFactorId);
75
        }
76
77
        return new self(self::STATUS_CHALLENGE_OK, $secondFactorId);
78
    }
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @return ProofOfPossessionResult
82
     */
83
    public static function tooManyAttempts(): self
84
    {
85
        return new self(self::STATUS_TOO_MANY_ATTEMPTS);
86
    }
87
88
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
89
     * @return bool
90
     */
91
    public function isSuccessful(): bool
92
    {
93
        return $this->status === self::STATUS_CHALLENGE_OK && $this->secondFactorId !== null;
94
    }
95
96
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
97
     * @return null|string
98
     */
99
    public function getSecondFactorId()
100
    {
101
        return $this->secondFactorId;
102
    }
103
104
    public function didProofOfPossessionFail(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function didProofOfPossessionFail()
Loading history...
105
    {
106
        return $this->status === self::STATUS_CHALLENGE_OK && $this->secondFactorId === null;
107
    }
108
109
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
110
     * @return boolean
111
     */
112
    public function wasIncorrectChallengeResponseGiven(): bool
113
    {
114
        return $this->status === self::STATUS_INCORRECT_CHALLENGE;
115
    }
116
117
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
118
     * @return boolean
119
     */
120
    public function hasChallengeExpired(): bool
121
    {
122
        return $this->status === self::STATUS_CHALLENGE_EXPIRED;
123
    }
124
125
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
126
     * @return boolean
127
     */
128
    public function wereTooManyAttemptsMade(): bool
129
    {
130
        return $this->status === self::STATUS_TOO_MANY_ATTEMPTS;
131
    }
132
}
133