Test Failed
Push — master ( 31150b...7a8e59 )
by Mike
06:11
created

SecurityProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

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