RedisManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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