AccessToken   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 47
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __toString() 0 4 1
A getName() 0 4 1
A getToken() 0 4 1
A getExpires() 0 8 1
A setToken() 0 7 1
1
<?php
2
3
namespace Happyr\GoogleSiteAuthenticatorBundle\Model;
4
5
/**
6
 * This is the access token model that will be saved in the cache storage.
7
 */
8
class AccessToken
9
{
10
    private $name;
11
    private $token;
12
    private $createdAt;
13
    private $updatedAt;
14
15
    public function __construct(string $name, string $token)
16
    {
17
        $this->name = $name;
18
        $this->token = $token;
19
        $this->createdAt = new \DateTimeImmutable();
20
        $this->updatedAt = new \DateTimeImmutable();
21
    }
22
23
    public function __toString()
24
    {
25
        return $this->getToken();
26
    }
27
28
    public function getName(): string
29
    {
30
        return $this->name ?? '';
31
    }
32
33
    public function getToken(): string
34
    {
35
        return $this->token ?? '';
36
    }
37
38
    public function getExpires(): \DateTimeInterface
39
    {
40
        $data = \json_decode($this->getToken(), true);
41
        $exp = new \DateTimeImmutable();
42
43
        return $exp->setTimestamp($data['created'])
44
            ->modify('+'.$data['expires_in'].'seconds');
45
    }
46
47
    public function setToken(string $token): self
48
    {
49
        $this->token = $token;
50
        $this->updatedAt = new \DateTimeImmutable();
51
52
        return $this;
53
    }
54
}
55