Passed
Push — master ( 08ce64...4483b1 )
by Mike
02:47
created

SecurityProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 60
ccs 14
cts 18
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A add() 0 3 1
A get() 0 12 2
A authenticate() 0 3 1
1
<?php
2
3
4
namespace Xervice\Security\Business\Model\Provider;
5
6
7
use DataProvider\AuthenticatorDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\AuthenticatorDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Xervice\Security\Business\Dependency\Authenticator\AuthenticatorInterface;
9
use Xervice\Security\Business\Exception\SecurityException;
10
11
class SecurityProvider implements SecurityProviderInterface
12
{
13
    /**
14
     * @var \Xervice\Security\Business\Dependency\Authenticator\AuthenticatorInterface[]
15
     */
16
    private $authenticatorList;
17
18
    /**
19
     * SecurityProvider constructor.
20
     *
21
     * @param array $authenticatorList
22
     */
23 3
    public function __construct(array $authenticatorList)
24
    {
25 3
        foreach ($authenticatorList as $name => $authClass) {
26 3
            $this->add(
27 3
                $name,
28 3
                new $authClass()
29
            );
30
        }
31 3
    }
32
33
    /**
34
     * @param string $name
35
     * @param \Xervice\Security\Business\Dependency\Authenticator\AuthenticatorInterface $authenticator
36
     */
37 3
    public function add(string $name, AuthenticatorInterface $authenticator): void
38
    {
39 3
        $this->authenticatorList[$name] = $authenticator;
40 3
    }
41
42
    /**
43
     * @param string $name
44
     *
45
     * @return \Xervice\Security\Business\Dependency\Authenticator\AuthenticatorInterface
46
     * @throws \Xervice\Security\Business\Exception\SecurityException
47
     */
48 3
    public function get(string $name): AuthenticatorInterface
49
    {
50 3
        if (!isset($this->authenticatorList[$name])) {
51
            throw new SecurityException(
52
                sprintf(
53
                    'Authenticator %s does not exist',
54
                    $name
55
                )
56
            );
57
        }
58
59 3
        return $this->authenticatorList[$name];
60
    }
61
62
    /**
63
     * @param string $name
64
     * @param \DataProvider\AuthenticatorDataProvider $dataProvider
65
     *
66
     * @throws \Xervice\Security\Business\Exception\SecurityException
67
     */
68 3
    public function authenticate(string $name, AuthenticatorDataProvider $dataProvider): void
69
    {
70 3
        $this->get($name)->authenticate($dataProvider);
71
    }
72
}