HistoryFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 10
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createPlugin() 0 15 3
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\HistoryPlugin;
9
use Http\Client\Common\Plugin\Journal;
10
use InvalidArgumentException;
11
use Psr\Container\ContainerInterface;
12
13
class HistoryFactory implements PluginFactory
14
{
15
    private ContainerInterface $container;
16
17
    public function __construct(ContainerInterface $container)
18 1
    {
19
        $this->container = $container;
20 1
    }
21 1
22
    /**
23
     * @param array<string, mixed> $config
24
     */
25
    public function createPlugin(array $config = []): Plugin
26
    {
27
        $journalServiceName = $config['journal'] ?? null;
28 1
29
        if (! \is_string($journalServiceName)) {
30 1
            throw new InvalidArgumentException('Invalid "journal" parameter');
31
        }
32 1
33
        $journal = $this->container->get($journalServiceName);
34
35
        if (! $journal instanceof Journal) {
36 1
            throw new InvalidArgumentException('Invalid "journal" service');
37
        }
38 1
39
        return new HistoryPlugin($journal);
40
    }
41
}
42