MonzoCredentials::getMonzoUserIdColumn()   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 0
1
<?php
2
3
namespace Amelia\Monzo;
4
5
use Laravel\Socialite\Two\User;
6
7
trait MonzoCredentials
8
{
9
    /**
10
     * Set a user's credentials from a user object returned via Socialite.
11
     *
12
     * @param \Laravel\Socialite\Two\User $user
13
     * @return $this
14
     */
15
    public function setMonzoUser(User $user)
16
    {
17
        $this->setAttribute($this->getMonzoAccessTokenColumn(), $user->token);
18
        $this->setAttribute($this->getMonzoRefreshTokenColumn(), $user->refreshToken);
19
        $this->setAttribute($this->getMonzoUserIdColumn(), $user->id);
20
21
        return $this;
22
    }
23
24
    /**
25
     * Update this object to set new credentials.
26
     *
27
     * @param string $token
28
     * @param string $refreshToken
29
     * @return void
30
     */
31
    public function updateMonzoCredentials(string $token, string $refreshToken)
32
    {
33
        $this->setAttribute($this->getMonzoAccessTokenColumn(), $token);
34
        $this->setAttribute($this->getMonzoRefreshTokenColumn(), $refreshToken);
35
36
        $this->save();
37
    }
38
39
    /**
40
     * Get a monzo user's access token.
41
     *
42
     * @return string|null
43
     */
44
    public function getMonzoAccessToken()
45
    {
46
        return $this->getAttribute($this->getMonzoAccessTokenColumn());
47
    }
48
49
    /**
50
     * Get a monzo user's refresh token.
51
     *
52
     * @return string|null
53
     */
54
    public function getMonzoRefreshToken()
55
    {
56
        return $this->getAttribute($this->getMonzoRefreshTokenColumn());
57
    }
58
59
    /**
60
     * Get a monzo user's refresh token.
61
     *
62
     * @return string|null
63
     */
64
    public function getMonzoUserId()
65
    {
66
        return $this->getAttribute($this->getMonzoUserIdColumn());
67
    }
68
69
    /**
70
     * Get a user's monzo email.
71
     *
72
     * @return string
73
     */
74
    public function getMonzoEmail()
75
    {
76
        return $this->getAttribute($this->getMonzoEmailColumn());
77
    }
78
79
    /**
80
     * Get the attribute name for a monzo user's access token.
81
     *
82
     * @return string
83
     */
84
    protected function getMonzoAccessTokenColumn()
85
    {
86
        return 'monzo_access_token';
87
    }
88
89
    /**
90
     * Get the attribute name for a monzo user's refresh token.
91
     *
92
     * @return string
93
     */
94
    protected function getMonzoRefreshTokenColumn()
95
    {
96
        return 'monzo_refresh_token';
97
    }
98
99
    /**
100
     * Get the attribute name for a monzo user's id.
101
     *
102
     * @return string
103
     */
104
    protected function getMonzoUserIdColumn()
105
    {
106
        return 'monzo_user_id';
107
    }
108
109
    /**
110
     * Get the attribute name for a monzo user's email.
111
     *
112
     * @return string
113
     */
114
    protected function getMonzoEmailColumn()
115
    {
116
        return 'email';
117
    }
118
}
119