RedisManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getClient() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Redis\Business\Redis;
15
16
use Micro\Plugin\Redis\RedisPluginConfiguration;
17
use Micro\Plugin\Redis\RedisPluginConfigurationInterface;
18
19
class RedisManager implements RedisManagerInterface
20
{
21
    /**
22
     * @var array<string, \Redis>
23
     */
24
    private array $redisCollection;
25
26 2
    public function __construct(
27
        private readonly RedisFactoryInterface $redisFactory,
28
        private readonly RedisPluginConfigurationInterface $redisPluginConfiguration
29
    ) {
30 2
        $this->redisCollection = [];
31
    }
32
33 2
    public function getClient(string $clientName = RedisPluginConfiguration::CLIENT_DEFAULT): \Redis
34
    {
35 2
        if (\array_key_exists($clientName, $this->redisCollection)) {
36 1
            return $this->redisCollection[$clientName];
37
        }
38
39 2
        $config = $this->redisPluginConfiguration->getClientConfiguration($clientName);
40 2
        $redis = $this->redisFactory->create($config);
41
42 1
        return $this->redisCollection[$clientName] = $redis;
43
    }
44
}
45