AccessToken   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 7
c 5
b 1
f 2
lcom 1
cbo 1
dl 0
loc 49
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getToken() 0 4 1
A getExpiresAt() 0 4 1
A getScopes() 0 4 1
A getClientId() 0 4 1
A __construct() 0 10 1
A getResourceOwner() 0 4 1
A isExpired() 0 4 1
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