AuthProvider::__construct()   A
last analyzed

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
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\User\Business\Model\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\Model\Authenticator\UserCredentialProviderInterface
14
     */
15
    private $credentialProvider;
16
17
    /**
18
     * @var \Xervice\User\Business\Dependency\Authenticator\Login\LoginInterface[]
19
     */
20
    private $loginCollection;
21
22
    /**
23
     * AuthProvider constructor.
24
     *
25
     * @param \Xervice\User\Business\Model\Authenticator\UserCredentialProviderInterface $credentialProvider
26
     * @param \Xervice\User\Business\Dependency\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 \DataProvider\UserAuthDataProvider $authDataProvider
38
     *
39
     * @return bool
40
     * @throws \Xervice\User\Business\Exception\UserException
41
     */
42 1
    public function auth(UserAuthDataProvider $authDataProvider): bool
43
    {
44 1
        $login = $this->loginCollection[$authDataProvider->getType()] ?? null;
45
46 1
        if (!$login) {
47 1
            throw new UserException(
48 1
                sprintf(
49 1
                    'Login type %s not found',
50 1
                    $authDataProvider->getType()
51
                )
52
            );
53
        }
54
55
        return $login->auth(
56
            $authDataProvider,
57
            $this->credentialProvider->getCredentialsForType(
58
                $authDataProvider->getUser(),
59
                $authDataProvider->getType()
60
            )
61
        );
62
    }
63
}