Passed
Pull Request — main (#308)
by Paul
13:29 queued 06:46
created

ProofOfPossessionResult   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 75
rs 10
c 1
b 0
f 0
wmc 15
1
<?php
2
3
/**
4
 * Copyright 2022 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
 */
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...
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens;
20
21
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
 * @SuppressWarnings(PHPMD.TooManyMethods)
23
 */
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...
24
final readonly class ProofOfPossessionResult
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 24 at column 6
Loading history...
25
{
26
    public const STATUS_CHALLENGE_OK = 0;
27
    public const STATUS_INCORRECT_CHALLENGE = 1;
28
    public const STATUS_CHALLENGE_EXPIRED = 2;
29
    public const STATUS_TOO_MANY_ATTEMPTS = 3;
30
31
    private function __construct(private int $status, private ?string $recoveryTokenId = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
32
    {
33
    }
34
35
    public static function challengeExpired(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function challengeExpired()
Loading history...
36
    {
37
        return new self(self::STATUS_CHALLENGE_EXPIRED);
38
    }
39
40
    public static function incorrectChallenge(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function incorrectChallenge()
Loading history...
41
    {
42
        return new self(self::STATUS_INCORRECT_CHALLENGE);
43
    }
44
45
    public static function proofOfPossessionCommandFailed(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function proofOfPossessionCommandFailed()
Loading history...
46
    {
47
        return new self(self::STATUS_CHALLENGE_OK);
48
    }
49
50
    public static function recoveryTokenCreated(string $recoveryTokenId): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function recoveryTokenCreated()
Loading history...
51
    {
52
        return new self(self::STATUS_CHALLENGE_OK, $recoveryTokenId);
53
    }
54
55
    public static function recoveryTokenVerified(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function recoveryTokenVerified()
Loading history...
56
    {
57
        return new self(self::STATUS_CHALLENGE_OK);
58
    }
59
60
    public static function tooManyAttempts(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tooManyAttempts()
Loading history...
61
    {
62
        return new self(self::STATUS_TOO_MANY_ATTEMPTS);
63
    }
64
65
    public function isSuccessful(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isSuccessful()
Loading history...
66
    {
67
        return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId !== null;
68
    }
69
70
    public function authenticated(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function authenticated()
Loading history...
71
    {
72
        return $this->status === self::STATUS_CHALLENGE_OK;
73
    }
74
75
    public function didProofOfPossessionFail(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function didProofOfPossessionFail()
Loading history...
76
    {
77
        return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId === null;
78
    }
79
80
    public function wasIncorrectChallengeResponseGiven(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function wasIncorrectChallengeResponseGiven()
Loading history...
81
    {
82
        return $this->status === self::STATUS_INCORRECT_CHALLENGE;
83
    }
84
85
    public function hasChallengeExpired(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function hasChallengeExpired()
Loading history...
86
    {
87
        return $this->status === self::STATUS_CHALLENGE_EXPIRED;
88
    }
89
90
    public function wereTooManyAttemptsMade(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function wereTooManyAttemptsMade()
Loading history...
91
    {
92
        return $this->status === self::STATUS_TOO_MANY_ATTEMPTS;
93
    }
94
}
95