HistoryFactory::createPlugin()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

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