HandleOauth::oauthUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace A17\Twill\Repositories\Behaviors;
4
5
trait HandleOauth
6
{
7
8
    /**
9
     * @param \Laravel\Socialite\Contracts\User $oauthUser
10
     * @return \A17\Twill\Models\User
11
     */
12
    public function oauthUser($oauthUser)
13
    {
14
        return $this->model->whereEmail($oauthUser->email)->first();
0 ignored issues
show
Bug introduced by
Accessing email on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
15
    }
16
17
    /**
18
     * @param \Laravel\Socialite\Contracts\User $oauthUser
19
     * @param string $provider
20
     * @return boolean
21
     */
22
    public function oauthIsUserLinked($oauthUser, $provider)
23
    {
24
        $user = $this->model->whereEmail($oauthUser->email)->first();
0 ignored issues
show
Bug introduced by
Accessing email on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
26
        return $user->providers()
27
            ->where(['provider' => $provider, 'oauth_id' => $oauthUser->id])
0 ignored issues
show
Bug introduced by
Accessing id on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
28
            ->exists();
29
    }
30
31
    /**
32
     * @param \Laravel\Socialite\Contracts\User $oauthUser
33
     * @param string $provider
34
     * @return \A17\Twill\Models\User
35
     */
36
    public function oauthUpdateProvider($oauthUser, $provider)
37
    {
38
        $user = $this->model->whereEmail($oauthUser->email)->first();
0 ignored issues
show
Bug introduced by
Accessing email on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
        $provider = $user->providers()
40
            ->where(['provider' => $provider, 'oauth_id' => $oauthUser->id])
0 ignored issues
show
Bug introduced by
Accessing id on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
41
            ->first();
42
43
        $provider->token = $oauthUser->token;
0 ignored issues
show
Bug introduced by
Accessing token on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
44
        $provider->avatar = $oauthUser->avatar;
0 ignored issues
show
Bug introduced by
Accessing avatar on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
45
        $provider->save();
46
47
        return $user;
48
    }
49
50
    /**
51
     * @param \Laravel\Socialite\Contracts\User $oauthUser
52
     * @return \A17\Twill\Models\User
53
     */
54
    public function oauthCreateUser($oauthUser)
55
    {
56
57
        $user = $this->model->firstOrNew([
58
            'name' => $oauthUser->name,
0 ignored issues
show
Bug introduced by
Accessing name on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
59
            'email' => $oauthUser->email,
0 ignored issues
show
Bug introduced by
Accessing email on the interface Laravel\Socialite\Contracts\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
60
            'role' => config('twill.oauth.default_role'),
61
            'published' => true,
62
        ]);
63
64
        $user->save();
65
66
        return $user;
67
68
    }
69
70
}
71