Passed
Pull Request — main (#308)
by Paul
18:42 queued 09:10
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
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2022 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\SelfAssertedTokens;
22
23
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
 * @SuppressWarnings(PHPMD.TooManyMethods)
25
 */
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...
26
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 26 at column 6
Loading history...
27
{
28
    public const STATUS_CHALLENGE_OK = 0;
29
    public const STATUS_INCORRECT_CHALLENGE = 1;
30
    public const STATUS_CHALLENGE_EXPIRED = 2;
31
    public const STATUS_TOO_MANY_ATTEMPTS = 3;
32
33
    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...
34
    {
35
    }
36
37
    public static function challengeExpired(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function challengeExpired()
Loading history...
38
    {
39
        return new self(self::STATUS_CHALLENGE_EXPIRED);
40
    }
41
42
    public static function incorrectChallenge(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function incorrectChallenge()
Loading history...
43
    {
44
        return new self(self::STATUS_INCORRECT_CHALLENGE);
45
    }
46
47
    public static function proofOfPossessionCommandFailed(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function proofOfPossessionCommandFailed()
Loading history...
48
    {
49
        return new self(self::STATUS_CHALLENGE_OK);
50
    }
51
52
    public static function recoveryTokenCreated(string $recoveryTokenId): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function recoveryTokenCreated()
Loading history...
53
    {
54
        return new self(self::STATUS_CHALLENGE_OK, $recoveryTokenId);
55
    }
56
57
    public static function recoveryTokenVerified(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function recoveryTokenVerified()
Loading history...
58
    {
59
        return new self(self::STATUS_CHALLENGE_OK);
60
    }
61
62
    public static function tooManyAttempts(): ProofOfPossessionResult
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tooManyAttempts()
Loading history...
63
    {
64
        return new self(self::STATUS_TOO_MANY_ATTEMPTS);
65
    }
66
67
    public function isSuccessful(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isSuccessful()
Loading history...
68
    {
69
        return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId !== null;
70
    }
71
72
    public function authenticated(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function authenticated()
Loading history...
73
    {
74
        return $this->status === self::STATUS_CHALLENGE_OK;
75
    }
76
77
    public function didProofOfPossessionFail(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function didProofOfPossessionFail()
Loading history...
78
    {
79
        return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId === null;
80
    }
81
82
    public function wasIncorrectChallengeResponseGiven(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function wasIncorrectChallengeResponseGiven()
Loading history...
83
    {
84
        return $this->status === self::STATUS_INCORRECT_CHALLENGE;
85
    }
86
87
    public function hasChallengeExpired(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function hasChallengeExpired()
Loading history...
88
    {
89
        return $this->status === self::STATUS_CHALLENGE_EXPIRED;
90
    }
91
92
    public function wereTooManyAttemptsMade(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function wereTooManyAttemptsMade()
Loading history...
93
    {
94
        return $this->status === self::STATUS_TOO_MANY_ATTEMPTS;
95
    }
96
}
97