TokenEntityTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 84
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setClient() 0 3 1
A setUserIdentifier() 0 3 1
A getExpiryDateTime() 0 3 1
A getClient() 0 3 1
A getUserIdentifier() 0 3 1
A addScope() 0 3 1
A setExpiryDateTime() 0 3 1
A getScopes() 0 3 1
1
<?php
2
3
/**
4
 * @author      Alex Bilbie <[email protected]>
5
 * @copyright   Copyright (c) Alex Bilbie
6
 * @license     http://mit-license.org/
7
 *
8
 * @link        https://github.com/thephpleague/oauth2-server
9
 */
10
11
declare(strict_types=1);
12
13
namespace League\OAuth2\Server\Entities\Traits;
14
15
use DateTimeImmutable;
16
use League\OAuth2\Server\Entities\ClientEntityInterface;
17
use League\OAuth2\Server\Entities\ScopeEntityInterface;
18
19
use function array_values;
20
21
trait TokenEntityTrait
22
{
23
    /**
24
     * @var ScopeEntityInterface[]
25
     */
26
    protected array $scopes = [];
27
28
    protected DateTimeImmutable $expiryDateTime;
29
30
    /**
31
     * @var non-empty-string|null
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
32
     */
33
    protected string|null $userIdentifier = null;
34
35
    protected ClientEntityInterface $client;
36
37
    /**
38
     * Associate a scope with the token.
39
     */
40 8
    public function addScope(ScopeEntityInterface $scope): void
41
    {
42 8
        $this->scopes[$scope->getIdentifier()] = $scope;
43
    }
44
45
    /**
46
     * Return an array of scopes associated with the token.
47
     *
48
     * @return ScopeEntityInterface[]
49
     */
50 13
    public function getScopes(): array
51
    {
52 13
        return array_values($this->scopes);
53
    }
54
55
    /**
56
     * Get the token's expiry date time.
57
     */
58 19
    public function getExpiryDateTime(): DateTimeImmutable
59
    {
60 19
        return $this->expiryDateTime;
61
    }
62
63
    /**
64
     * Set the date time when the token expires.
65
     */
66 49
    public function setExpiryDateTime(DateTimeImmutable $dateTime): void
67
    {
68 49
        $this->expiryDateTime = $dateTime;
69
    }
70
71
    /**
72
     * Set the identifier of the user associated with the token.
73
     *
74
     * @param non-empty-string $identifier The identifier of the user
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
75
     */
76 20
    public function setUserIdentifier(string $identifier): void
77
    {
78 20
        $this->userIdentifier = $identifier;
79
    }
80
81
    /**
82
     * Get the token user's identifier.
83
     *
84
     * @return non-empty-string|null
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
85
     */
86 17
    public function getUserIdentifier(): string|null
87
    {
88 17
        return $this->userIdentifier;
89
    }
90
91
    /**
92
     * Get the client that the token was issued to.
93
     */
94 17
    public function getClient(): ClientEntityInterface
95
    {
96 17
        return $this->client;
97
    }
98
99
    /**
100
     * Set the client that the token was issued to.
101
     */
102 26
    public function setClient(ClientEntityInterface $client): void
103
    {
104 26
        $this->client = $client;
105
    }
106
}
107