Passed
Push — master ( 106006...c1ddb5 )
by Thomas Mauro
06:38 queued 11s
created

AuthMethodFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A __construct() 0 4 2
A all() 0 3 1
A create() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\AuthMethod;
6
7
use TMV\OpenIdClient\Exception\InvalidArgumentException;
8
9
final class AuthMethodFactory implements AuthMethodFactoryInterface
10
{
11
    /** @var AuthMethodInterface[] */
12
    private $methods = [];
13
14
    /**
15
     * AuthMethodFactory constructor.
16
     *
17
     * @param AuthMethodInterface[] $methods
18
     */
19 3
    public function __construct(array $methods = [])
20
    {
21 3
        foreach ($methods as $method) {
22 2
            $this->add($method);
23
        }
24 3
    }
25
26 2
    public function add(AuthMethodInterface $authMethod): void
27
    {
28 2
        $this->methods[$authMethod->getSupportedMethod()] = $authMethod;
29 2
    }
30
31
    /**
32
     * @return AuthMethodInterface[]
33
     */
34 1
    public function all(): array
35
    {
36 1
        return $this->methods;
37
    }
38
39 2
    public function create(string $authMethod): AuthMethodInterface
40
    {
41 2
        $method = $this->methods[$authMethod] ?? null;
42
43 2
        if (null === $method) {
44 1
            throw new InvalidArgumentException('Unsupported auth method "' . $authMethod . '"');
45
        }
46
47 1
        return $method;
48
    }
49
}
50