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

HasOauth::linkProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 2
rs 10
c 1
b 0
f 0
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