PasswordCredentials   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
c 0
b 0
f 0
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A password() 0 8 2
A isResolved() 0 3 1
A markResolved() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of web-stack
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\WebStack\Domain\Security\Http\Authenticator\Passport\Badge\Credentials;
13
14
use Slick\WebStack\Domain\Security\Exception\LogicException;
15
use Slick\WebStack\Domain\Security\Http\Authenticator\Passport\Badge\CredentialsInterface;
16
use SensitiveParameter;
0 ignored issues
show
Bug introduced by
The type SensitiveParameter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * PasswordCredentials
20
 *
21
 * @package Slick\WebStack\Domain\Security\Http\Authenticator\Passport\Badge\Credentials
22
 */
23
class PasswordCredentials implements CredentialsInterface
24
{
25
26
    private bool $resolved = false;
27
    private ?string $password;
28
29
    public function __construct(#[SensitiveParameter] string $password)
30
    {
31
        $this->password = $password;
32
    }
33
34
    /**
35
     * PasswordCredentials password
36
     *
37
     * @return string
38
     */
39
    public function password(): string
40
    {
41
        if (null === $this->password) {
42
            throw new LogicException(
43
                'The credentials are erased as another listener already verified these credentials.'
44
            );
45
        }
46
        return $this->password;
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function isResolved(): bool
53
    {
54
        return $this->resolved;
55
    }
56
57
    /**
58
     * Marks the credentials badge as resolved.
59
     *
60
     * @return void
61
     */
62
    public function markResolved(): void
63
    {
64
        $this->password = null;
65
        $this->resolved = true;
66
    }
67
}
68