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

RefreshToken::getToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 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