Completed
Push — master ( 5b54fc...16c96d )
by Bertrand
14:42
created

SocialiteGatewayImpl::user()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 16
nop 1
dl 0
loc 18
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Gateway;
5
6
7
use App\Src\UseCases\Domain\Auth\SocialiteUser;
8
use App\Src\UseCases\Domain\Shared\Gateway\SocialiteGateway;
9
use Laravel\Socialite\Facades\Socialite;
10
11
class SocialiteGatewayImpl implements SocialiteGateway
12
{
13
    public function user(string $provider): SocialiteUser
14
    {
15
        if($provider === 'twitter'){
16
            $user = Socialite::driver($provider)->user();
17
        }else {
18
            $user = Socialite::driver($provider)->stateless()->user();
0 ignored issues
show
Bug introduced by
The method stateless() does not exist on Laravel\Socialite\Contracts\Provider. It seems like you code against a sub-type of Laravel\Socialite\Contracts\Provider such as Laravel\Socialite\Two\AbstractProvider. ( Ignorable by Annotation )

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

18
            $user = Socialite::driver($provider)->/** @scrutinizer ignore-call */ stateless()->user();
Loading history...
19
        }
20
21
        $email = $user->getEmail();
22
        $firstname = $user->getNickname() !== null ? $user->getNickname() : $user->getName();
23
        if(isset($user->user['given_name'])){
24
            $firstname = $user->user['given_name'];
25
        }
26
        $lastname = isset($user->user['family_name']) ? $user->user['family_name'] : $user->getName();
27
        $id = $user->getId();
28
        $picture = $user->getAvatar();
29
30
        return new SocialiteUser($id, $email, $firstname, $lastname, $picture);
31
    }
32
}
33