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

SocialiteGatewayImpl   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A user() 0 18 5
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