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

TokenEntityTrait::setUserIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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