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

AuthMethodFactory::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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