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

AuthProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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
}