Passed
Pull Request — master (#1470)
by
unknown
33:34
created

TokenEntityTrait::setScopes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 10
    public function addScope(ScopeEntityInterface $scope): void
41
    {
42 10
        $this->scopes[$scope->getIdentifier()] = $scope;
43
    }
44
45
    /**
46
     * Return an array of scopes associated with the token.
47
     *
48
     * @return ScopeEntityInterface[]
49
     */
50 15
    public function getScopes(): array
51
    {
52 15
        return array_values($this->scopes);
53
    }
54
55
    /**
56
     * Set the scopes array (doesn't check for duplicates)
57
     * 
58 21
     * @param array scopes
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\Entities\Traits\scopes 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...
59
     */
60 21
    public function setScopes(array $scopes): void
61
    {
62
        $this->scopes = $scopes;
63
    }
64
65
    /**
66 52
     * Get the token's expiry date time.
67
     */
68 52
    public function getExpiryDateTime(): DateTimeImmutable
69
    {
70
        return $this->expiryDateTime;
71
    }
72
73
    /**
74
     * Set the date time when the token expires.
75
     */
76 20
    public function setExpiryDateTime(DateTimeImmutable $dateTime): void
77
    {
78 20
        $this->expiryDateTime = $dateTime;
79
    }
80
81
    /**
82
     * Set the identifier of the user associated with the token.
83
     *
84
     * @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...
85
     */
86 19
    public function setUserIdentifier(?string $identifier): void
87
    {
88 19
        $this->userIdentifier = $identifier;
89
    }
90
91
    /**
92
     * Get the token user's identifier.
93
     *
94 18
     * @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...
95
     */
96 18
    public function getUserIdentifier(): ?string
97
    {
98
        return $this->userIdentifier;
99
    }
100
101
    /**
102 28
     * Get the client that the token was issued to.
103
     */
104 28
    public function getClient(): ClientEntityInterface
105
    {
106
        return $this->client;
107
    }
108
109
    /**
110
     * Set the client that the token was issued to.
111
     */
112
    public function setClient(ClientEntityInterface $client): void
113
    {
114
        $this->client = $client;
115
    }
116
}
117