RedisFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Cache;
6
7
use Predis\Client as PredisClient;
8
use Psr\Container\ContainerInterface;
9
10
use function count;
11
use function explode;
12
use function is_string;
13
14
class RedisFactory
15
{
16
    public const SERVICE_NAME = 'Shlinkio\Shlink\Common\Cache\Redis';
17
18 12
    public function __invoke(ContainerInterface $container): PredisClient
19
    {
20 12
        $config = $container->get('config');
21 12
        $redisConfig = $config['cache']['redis'] ?? $config['redis'] ?? [];
22
23 12
        $servers = $redisConfig['servers'] ?? [];
24 12
        $servers = is_string($servers) ? explode(',', $servers) : $servers;
25 12
        $options = count($servers) <= 1 ? null : ['cluster' => 'redis'];
26
27 12
        return new PredisClient($servers, $options);
28
    }
29
}
30