Test Failed
Push — master ( fe954a...0e0ddf )
by Mike
02:18
created

AuthProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 51
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A auth() 0 18 2
1
<?php
2
3
4
namespace Xervice\User\Business\Authenticator;
5
6
7
use DataProvider\UserAuthDataProvider;
8
use Xervice\User\Business\Exception\UserException;
9
10
class AuthProvider implements AuthProviderInterface
11
{
12
    /**
13
     * @var \Xervice\User\Business\Authenticator\UserCredentialProviderInterface
14
     */
15
    private $credentialProvider;
16
17
    /**
18
     * @var \Xervice\User\Business\Authenticator\Login\LoginInterface[]
19
     */
20
    private $loginCollection;
21
22
    /**
23
     * AuthProvider constructor.
24
     *
25
     * @param \Xervice\User\Business\Authenticator\UserCredentialProviderInterface $credentialProvider
26
     * @param \Xervice\User\Business\Authenticator\Login\LoginInterface[] $loginCollection
27
     */
28
    public function __construct(
29
        UserCredentialProviderInterface $credentialProvider,
30
        array $loginCollection
31
    ) {
32
        $this->credentialProvider = $credentialProvider;
33
        $this->loginCollection = $loginCollection;
34
    }
35
36
    /**
37
     * @param string $type
38
     * @param \DataProvider\UserAuthDataProvider $authDataProvider
39
     *
40
     * @return bool
41
     * @throws \Xervice\User\Business\Exception\UserException
42
     */
43
    public function auth(UserAuthDataProvider $authDataProvider): bool
44
    {
45
        $login = $this->loginCollection[$authDataProvider->getType()] ?? null;
46
47
        if (!$login) {
48
            throw new UserException(
49
                sprintf(
50
                    'Login type %s not found',
51
                    $authDataProvider->getType()
52
                )
53
            );
54
        }
55
56
        return $login->auth(
57
            $authDataProvider,
58
            $this->credentialProvider->getCredentialsForType(
59
                $authDataProvider->getUser(),
60
                $authDataProvider->getType()
61
            )
62
        );
63
    }
64
}