RememberMeToken   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 9
c 0
b 0
f 0
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __unserialize() 0 5 2
A __construct() 0 8 1
A __serialize() 0 3 1
A secret() 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\Authentication\Token;
13
14
use Slick\WebStack\Domain\Security\Authentication\TokenInterface;
15
use Slick\WebStack\Domain\Security\UserInterface;
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
 * RememberMeToken
20
 *
21
 * @package Slick\WebStack\Domain\Security\Authentication\Token
22
 *
23
 * @implements TokenInterface<UserInterface>
24
 */
25
final class RememberMeToken extends AbstractToken implements TokenInterface
26
{
27
28
    /**
29
     * Creates a RememberMeToken
30
     *
31
     * @param UserInterface $user
32
     * @phpstan-param UserInterface $user
33
     * @param string $secret
34
     */
35
    public function __construct(
36
        UserInterface $user,
37
        #[SensitiveParameter]
38
        private string $secret
39
    ) {
40
        $this->user = $user;
41
        $roles = $this->user()?->roles();
42
        parent::__construct($roles ?? []);
43
    }
44
45
    /**
46
     * RememberMeToken secret
47
     *
48
     * @return string
49
     */
50
    public function secret(): string
51
    {
52
        return $this->secret;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function __serialize(): array
59
    {
60
        return [$this->secret, parent::__serialize()];
61
    }
62
63
    /**
64
     * @inheritDoc
65
     * @param array<string|int, mixed> $data
66
     */
67
    public function __unserialize(array $data): void
68
    {
69
        [$this->secret, $parentData] = $data;
70
        $parentData = is_array($parentData) ? $parentData : unserialize($parentData);
71
        parent::__unserialize($parentData);
72
    }
73
}
74