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

RefreshToken::setRefreshToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

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