RedisMetricsHandlerFactory::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

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