Completed
Push — master ( f0e2f6...92b1b1 )
by Thijs
01:21
created

AccessToken   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 69
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromDevOps() 0 8 1
A expired() 0 4 1
A toArray() 0 8 1
1
<?php
2
3
namespace TestMonitor\DevOps;
4
5
use League\OAuth2\Client\Token\AccessToken as VSTSAccessToken;
6
7
class AccessToken
8
{
9
    /**
10
     * @var string
11
     */
12
    public $accessToken;
13
14
    /**
15
     * @var string
16
     */
17
    public $refreshToken;
18
19
    /**
20
     * @var string
21
     */
22
    public $expiresIn;
23
24
    /**
25
     * Token constructor.
26
     *
27
     * @param string $accessToken
28
     * @param string $refreshToken
29
     * @param int $expiresIn
30
     */
31 6
    public function __construct(string $accessToken = '', string $refreshToken = '', int $expiresIn = 0)
32
    {
33 6
        $this->accessToken = $accessToken;
34 6
        $this->refreshToken = $refreshToken;
35 6
        $this->expiresIn = $expiresIn;
0 ignored issues
show
Documentation Bug introduced by
The property $expiresIn was declared of type string, but $expiresIn is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
36 6
    }
37
38
    /**
39
     * @param \League\OAuth2\Client\Token\AccessToken $token
40
     *
41
     * @return \TestMonitor\DevOps\AccessToken
42
     */
43 2
    public static function fromDevOps(VSTSAccessToken $token)
44
    {
45 2
        return new self(
46 2
            $token->getToken(),
47 2
            $token->getRefreshToken(),
48 2
            $token->getExpires()
49
        );
50
    }
51
52
    /**
53
     * Determines if the access token has expired.
54
     *
55
     * @return bool
56
     */
57 5
    public function expired()
58
    {
59 5
        return ($this->expiresIn - time()) < 60;
60
    }
61
62
    /**
63
     * Returns the token as an array.
64
     *
65
     * @return array
66
     */
67 1
    public function toArray()
68
    {
69
        return [
70 1
            'access_token' => $this->accessToken,
71 1
            'refresh_token' => $this->refreshToken,
72 1
            'expires_in' => $this->expiresIn,
73
        ];
74
    }
75
}
76