StopwatchFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 19
ccs 5
cts 6
cp 0.8333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createPlugin() 0 7 2
A __construct() 0 3 1
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