AuthenticationFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 2
b 0
f 0
dl 0
loc 30
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createPlugin() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\HTTPlugModule\PluginFactory;
6
7
use Http\Client\Common\Plugin;
8
use Http\Client\Common\Plugin\AuthenticationPlugin;
9
use InvalidArgumentException;
10
11
class AuthenticationFactory implements PluginFactory
12
{
13
    /** @var array<string, Authentication\AuthenticationFactory> */
14
    private array $factories;
15
16
    /**
17
     * AuthenticationFactory constructor.
18
     *
19
     * @param array<string, Authentication\AuthenticationFactory> $factories
20
     */
21 1
    public function __construct(array $factories)
22
    {
23 1
        $this->factories = $factories;
24 1
    }
25
26
    /**
27
     * @param array<string, mixed> $config
28
     */
29
    public function createPlugin(array $config = []): Plugin
30
    {
31 1
        $options = $config['options'] ?? [];
32
        $type = $config['type'] ?? null;
33 1
34 1
        $authFactory = $this->factories[$type] ?? null;
35
36
        if (! $authFactory instanceof Authentication\AuthenticationFactory) {
37 1
            throw new InvalidArgumentException('Unsupported authentication type');
38
        }
39 1
40
        return new AuthenticationPlugin($authFactory->createAuthentication($options));
41
    }
42
}
43