Passed
Push — master ( 3cf6cb...68bea6 )
by Mike
02:42
created

AuthProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 68.75%

Importance

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

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 1
    public function __construct(
29
        UserCredentialProviderInterface $credentialProvider,
30
        array $loginCollection
31
    ) {
32 1
        $this->credentialProvider = $credentialProvider;
33 1
        $this->loginCollection = $loginCollection;
34 1
    }
35
36
    /**
37
     * @param string $type
38
     * @param \DataProvider\UserAuthDataProvider $authDataProvider
39
     *
40
     * @return bool
41
     * @throws \Xervice\User\Business\Exception\UserException
42
     */
43 1
    public function auth(UserAuthDataProvider $authDataProvider): bool
44
    {
45 1
        $login = $this->loginCollection[$authDataProvider->getType()] ?? null;
46
47 1
        if (!$login) {
48 1
            throw new UserException(
49 1
                sprintf(
50 1
                    'Login type %s not found',
51 1
                    $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
}