UsesTokens::setClientSecret()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Amelia\Monzo;
4
5
use Amelia\Monzo\Contracts\Client as ClientContract;
6
7
trait UsesTokens
8
{
9
    /**
10
     * Monzo client ID.
11
     *
12
     * @var string
13
     */
14
    protected $id;
15
16
    /**
17
     * Monzo client secret.
18
     *
19
     * @var string
20
     */
21
    protected $secret;
22
23
    /**
24
     * The API token we're using.
25
     *
26
     * @var string
27
     */
28
    protected $token;
29
30
    /**
31
     * Set the token for this request.
32
     *
33
     * @param string $token
34
     * @return ClientContract|$this
35
     */
36
    public function token(string $token)
37
    {
38
        $this->token = $token;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Issue an oauth request with client params set.
45
     *
46
     * @param string $refreshToken
47
     * @return array an array with refresh_token and access_token values.
48
     */
49
    public function refresh(string $refreshToken)
50
    {
51
        $result = $this->newClient()->call('POST', 'oauth2/token', [], [
52
            'client_id' => $this->id,
53
            'client_secret' => $this->secret,
54
            'refresh_token' => $refreshToken,
55
            'grant_type' => 'refresh_token',
56
        ]);
57
58
        // set the access token to the new one
59
        $this->token($result['access_token']);
60
61
        return $result;
62
    }
63
64
    /**
65
     * Set the client ID.
66
     *
67
     * @param string $id
68
     * @return void
69
     */
70
    public function setClientId(string $id)
71
    {
72
        $this->id = $id;
73
    }
74
75
    /**
76
     * Get the client ID.
77
     *
78
     * @return string
79
     */
80
    public function getClientId()
81
    {
82
        return $this->id;
83
    }
84
85
    /**
86
     * Set the client secret.
87
     *
88
     * @param string $secret
89
     * @return void
90
     */
91
    public function setClientSecret(string $secret)
92
    {
93
        $this->secret = $secret;
94
    }
95
}
96