Passed
Push — master ( 7a8e59...abf2d6 )
by Mike
03:41
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 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 3
    public function __construct(array $authenticatorList)
25
    {
26 3
        foreach ($authenticatorList as $name => $authClass) {
27 3
            $this->add(
28 3
                $name,
29 3
                new $authClass()
30
            );
31
        }
32 3
    }
33
34
    /**
35
     * @param string $name
36
     * @param \Xervice\Security\Business\Authenticator\AuthenticatorInterface $authenticator
37
     */
38 3
    public function add(string $name, AuthenticatorInterface $authenticator): void
39
    {
40 3
        $this->authenticatorList[$name] = $authenticator;
41 3
    }
42
43
    /**
44
     * @param string $name
45
     *
46
     * @return \Xervice\Security\Business\Authenticator\AuthenticatorInterface
47
     * @throws \Xervice\Security\Business\Exception\SecurityException
48
     */
49 3
    public function get(string $name): AuthenticatorInterface
50
    {
51 3
        if (!isset($this->authenticatorList[$name])) {
52
            throw new SecurityException(
53
                sprintf(
54
                    'Authenticator %s does not exist',
55
                    $name
56
                )
57
            );
58
        }
59
60 3
        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 3
    public function authenticate(string $name, AuthenticatorDataProvider $dataProvider): void
70
    {
71 3
        $this->get($name)->authenticate($dataProvider);
72
    }
73
}