OAuthToken   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 0
dl 0
loc 49
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAccessToken() 0 4 1
A hasExpired() 0 4 1
A getTokenType() 0 4 1
A getAuthorizationString() 0 4 1
A serialize() 0 6 1
A unserialize() 0 8 1
1
<?php
2
3
namespace NodeRED;
4
5
class OAuthToken implements \Serializable
6
{
7
    private $accessToken;
8
    private $expiryTime;
9
    private $tokenType;
10
11 4
    public function __construct($accessToken, $expirySeconds, $tokenType)
12
    {
13 4
        $this->accessToken = $accessToken;
14 4
        $this->expiryTime = time() + $expirySeconds;
15 4
        $this->tokenType = $tokenType;
16 4
    }
17
18 1
    public function getAccessToken()
19
    {
20 1
        return $this->accessToken;
21
    }
22
23 1
    public function hasExpired()
24
    {
25 1
        return time() > $this->expiryTime;
26
    }
27
28 1
    public function getTokenType()
29
    {
30 1
        return $this->tokenType;
31
    }
32
33 1
    public function getAuthorizationString()
34
    {
35 1
        return $this->getTokenType() . ' ' . $this->getAccessToken();
36
    }
37
38 1
    public function serialize()
39
    {
40 1
        $collected = [$this->accessToken, $this->expiryTime, $this->tokenType];
41
42 1
        return serialize($collected);
43
    }
44
45 1
    public function unserialize($data)
46
    {
47 1
        $collected = unserialize($data);
48
49 1
        $this->accessToken = $collected[0];
50 1
        $this->expiryTime = $collected[1];
51 1
        $this->tokenType = $collected[2];
52 1
    }
53
}
54