Passed
Pull Request — 1.2 (#558)
by
unknown
09:10
created

HasOauth   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 21
ccs 0
cts 9
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A providers() 0 4 1
A linkProvider() 0 11 1
1
<?php
2
3
namespace A17\Twill\Models\Behaviors;
4
5
use A17\Twill\Models\UserOauth;
6
7
trait HasOauth
8
{
9
10
    public function providers()
11
    {
12
13
        return $this->hasMany(UserOauth::class, 'user_id');
0 ignored issues
show
Bug introduced by
It seems like hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        return $this->/** @scrutinizer ignore-call */ hasMany(UserOauth::class, 'user_id');
Loading history...
14
15
    }
16
17
    public function linkProvider($oauthUser, $provider)
18
    {
19
20
        $provider = new UserOauth([
21
            'token'    => $oauthUser->token,
22
            'avatar'   => $oauthUser->avatar,
23
            'provider' => $provider,
24
            'oauth_id' => $oauthUser->id,
25
        ]);
26
27
        return $this->providers()->save($provider);
28
    }
29
30
}
31