StopwatchFactory::createPlugin()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 2
cts 3
cp 0.6667
rs 10
cc 2
nc 2
nop 1
crap 2.1481
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\CachePlugin;
9
use Http\Client\Common\Plugin\StopwatchPlugin;
10
use Psr\Container\ContainerInterface;
11
12
class StopwatchFactory implements PluginFactory
13
{
14
    private ContainerInterface $container;
15
16
    public function __construct(ContainerInterface $container)
17 1
    {
18
        $this->container = $container;
19 1
    }
20 1
21
    /**
22
     * @param array<string, mixed> $config
23
     */
24
    public function createPlugin(array $config = []): Plugin
25
    {
26
        if (! class_exists(CachePlugin::class)) {
27 1
            throw new \LogicException('To use the stopwatch plugin you need to install the "php-http/stopwatch-plugin" package.');
28
        }
29 1
30
        return new StopwatchPlugin($this->container->get($config['stopwatch']));
31
    }
32
}
33