Test Setup Failed
Push — master ( dcfdf2...6863da )
by guillaume
16:18 queued 10:15
created

LogUserFromSocialNetwork::checkProviderAllowed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Auth;
5
6
7
use App\Exceptions\Domain\ProviderNotSupported;
8
use App\Src\UseCases\Domain\Ports\UserRepository;
9
use App\Src\UseCases\Infra\Gateway\Auth\AuthGateway;
10
use App\Src\UseCases\Infra\Gateway\Auth\SocialiteGateway;
11
12
class LogUserFromSocialNetwork
13
{
14
    private $allowedProviders = ['facebook', 'twitter', 'google'];
15
16
    private $userRepository;
17
    private $socialiteGateway;
18
    private $authGateway;
19
20
    public function __construct(
21
        UserRepository $userRepository,
22
        SocialiteGateway $socialiteGateway,
23
        AuthGateway $authGateway
24
    )
25
    {
26
        $this->userRepository = $userRepository;
27
        $this->socialiteGateway = $socialiteGateway;
28
        $this->authGateway = $authGateway;
29
    }
30
31
    /**
32
     * @param string $provider
33
     * @throws ProviderNotSupported
34
     */
35
    public function log(string $provider)
36
    {
37
        $this->checkProviderAllowed($provider);
38
39
        $socialiteUser = $this->socialiteGateway->user($provider);
40
41
        $user = $this->userRepository->getByProvider($provider, $socialiteUser->providerId());
42
        $this->authGateway->log($user);
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $u of App\Src\UseCases\Infra\G...Auth\AuthGateway::log() does only seem to accept App\Src\UseCases\Domain\User, maybe add an additional type check? ( Ignorable by Annotation )

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

42
        $this->authGateway->log(/** @scrutinizer ignore-type */ $user);
Loading history...
43
    }
44
45
    /**
46
     * @param string $provider
47
     * @throws ProviderNotSupported
48
     */
49
    private function checkProviderAllowed(string $provider): void
50
    {
51
        if (!in_array($provider, $this->allowedProviders)) {
52
            throw new ProviderNotSupported();
53
        }
54
    }
55
}
56