PasswordCredentials::isResolved()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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