AccessToken::isExpired()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Bgy\OAuth2;
4
5
use Bgy\OAuth2\Utils\Ensure;
6
7
/**
8
 * @author Boris Guéry <[email protected]>
9
 */
10
class AccessToken
11
{
12
    private $accessToken;
13
    private $expiresAt;
14
    private $clientId;
15
    private $resourceOwner;
16
    private $scopes;
17
18
    public function __construct($token, \DateTimeImmutable $expiresAt, $clientId, ResourceOwner $resourceOwner = null, array $scopes = [])
19
    {
20
        Ensure::string($token);
21
22
        $this->accessToken     = $token;
23
        $this->expiresAt       = $expiresAt;
24
        $this->clientId        = $clientId;
25
        $this->resourceOwner   = $resourceOwner;
26
        $this->scopes          = $scopes;
27
    }
28
29
    public function getToken()
30
    {
31
        return $this->accessToken;
32
    }
33
34
    public function getExpiresAt()
35
    {
36
        return $this->expiresAt;
37
    }
38
39
    public function getScopes()
40
    {
41
        return $this->scopes;
42
    }
43
44
    public function getClientId()
45
    {
46
        return $this->clientId;
47
    }
48
49
    public function getResourceOwner()
50
    {
51
        return $this->resourceOwner;
52
    }
53
54
    public function isExpired()
55
    {
56
        return ($this->expiresAt < new \DateTime('now', new \DateTimeZone('UTC')));
57
    }
58
}
59