RedisMetricsHandlerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 20
ccs 3
cts 7
cp 0.4286
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A create() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
namespace BenTools\MercurePHP\Metrics\Redis;
4
5
use BenTools\MercurePHP\Helpers\RedisHelper;
6
use BenTools\MercurePHP\Metrics\MetricsHandlerFactoryInterface;
7
use Clue\React\Redis\Client as AsynchronousClient;
8
use Clue\React\Redis\Factory;
9
use React\EventLoop\LoopInterface;
10
use React\Promise\PromiseInterface;
11
12
final class RedisMetricsHandlerFactory implements MetricsHandlerFactoryInterface
13
{
14
    private LoopInterface $loop;
15
16
    public function __construct(LoopInterface $loop)
17
    {
18 2
        $this->loop = $loop;
19
    }
20 2
21 2
    public function supports(string $dsn): bool
22
    {
23
        return RedisHelper::isRedisDSN($dsn);
24
    }
25
26
    public function create(string $dsn): PromiseInterface
27
    {
28
        $factory = new Factory($this->loop);
29
30
        return $factory->createClient($dsn)
31
            ->then(fn (AsynchronousClient $client) => new RedisMetricsHandler($client));
32
    }
33
}
34