AccessToken   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 87
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A __toString() 0 4 2
A hasToken() 0 4 1
A setExpiresAt() 0 6 1
A getExpiresAt() 0 4 1
A setToken() 0 6 1
A getToken() 0 4 1
1
<?php
2
3
namespace Happyr\LinkedIn;
4
5
/**
6
 * @author Tobias Nyholm
7
 */
8
class AccessToken
9
{
10
    /**
11
     * @var null|string token
12
     */
13
    private $token;
14
15
    /**
16
     * @var \DateTime expiresAt
17
     */
18
    private $expiresAt;
19
20
    /**
21
     * @param string        $token
22
     * @param \DateTime|int $expiresIn
23
     */
24 6
    public function __construct($token = null, $expiresIn = null)
25
    {
26 6
        $this->token = $token;
27
28 6
        if ($expiresIn !== null) {
29 2
            if ($expiresIn instanceof \DateTime) {
30 1
                $this->expiresAt = $expiresIn;
31 1
            } else {
32 2
                $this->expiresAt = new \DateTime(sprintf('+%dseconds', $expiresIn));
33
            }
34 2
        }
35 6
    }
36
37
    /**
38
     * @return string
39
     */
40 3
    public function __toString()
41
    {
42 3
        return $this->token ?: '';
43
    }
44
45
    /**
46
     * Does a token string exist?
47
     *
48
     * @return bool
49
     */
50 2
    public function hasToken()
51
    {
52 2
        return !empty($this->token);
53
    }
54
55
    /**
56
     * @param \DateTime $expiresAt
57
     *
58
     * @return $this
59
     */
60 1
    public function setExpiresAt(\DateTime $expiresAt = null)
61
    {
62 1
        $this->expiresAt = $expiresAt;
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * @return \DateTime
69
     */
70 2
    public function getExpiresAt()
71
    {
72 2
        return $this->expiresAt;
73
    }
74
75
    /**
76
     * @param null|string $token
77
     *
78
     * @return $this
79
     */
80 1
    public function setToken($token)
81
    {
82 1
        $this->token = $token;
83
84 1
        return $this;
85
    }
86
87
    /**
88
     * @return null|string
89
     */
90 1
    public function getToken()
91
    {
92 1
        return $this->token;
93
    }
94
}
95