Passed
Pull Request — master (#30)
by Daniel
03:08
created

RefreshToken   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaults() 0 4 1
A setRefreshToken() 0 4 1
A hasRefreshToken() 0 4 1
A getToken() 0 8 2
1
<?php
2
3
namespace Sainsburys\Guzzle\Oauth2\GrantType;
4
5
/**
6
 * Refresh token grant type.
7
 *
8
 * @link http://tools.ietf.org/html/rfc6749#section-6
9
 */
10
class RefreshToken extends GrantTypeBase implements RefreshTokenGrantTypeInterface
11
{
12
    const CONFIG_REFRESH_TOKEN = 'refresh_token';
13
14
    /**
15
     * @var string
16
     */
17
    protected $grantType = 'refresh_token';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 5
    protected function getDefaults()
23
    {
24 5
        return parent::getDefaults() + [self::CONFIG_REFRESH_TOKEN => ''];
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function setRefreshToken($refreshToken)
31
    {
32 3
        $this->config[self::CONFIG_REFRESH_TOKEN] = $refreshToken;
33 3
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function hasRefreshToken()
39
    {
40 3
        return !empty($this->config[self::CONFIG_REFRESH_TOKEN]);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function getToken()
47
    {
48 3
        if (!$this->hasRefreshToken()) {
49 1
            throw new \RuntimeException('Refresh token not available');
50
        }
51
52 2
        return parent::getToken();
53
    }
54
}
55