Completed
Push — master ( 0ced52...d99b90 )
by Markus
03:30
created

RedisServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createRedisClient() 0 13 1
A register() 0 3 1
1
<?php
2
3
namespace Jellyfish\Redis;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use Predis\Client;
8
9
class RedisServiceProvider implements ServiceProviderInterface
10
{
11
    /**
12
     * @param \Pimple\Container $pimple
13
     *
14
     * @return void
15
     */
16
    public function register(Container $pimple): void
17
    {
18
        $this->createRedisClient($pimple);
19
    }
20
21
    /**
22
     * @param \Pimple\Container $container
23
     *
24
     * @return \Pimple\ServiceProviderInterface
25
     */
26
    protected function createRedisClient(Container $container): ServiceProviderInterface
27
    {
28
        $config = $container->offsetGet('config');
29
30
        $container->offsetSet('redis_client', function () use ($config) {
31
            return new Client([
32
                'scheme' => 'tcp',
33
                'host' => $config->get(RedisConstants::REDIS_HOST, RedisConstants::DEFAULT_REDIS_HOST),
34
                'port' => $config->get(RedisConstants::REDIS_PORT, RedisConstants::DEFAULT_REDIS_PORT),
35
            ]);
36
        });
37
38
        return $this;
39
    }
40
}
41