RedisServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 3
b 0
f 0
wmc 2
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 25 2
1
<?php
2
3
namespace Ps2alerts\Api\ServiceProvider;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use Ps2alerts\Api\Contract\ConfigAwareInterface;
7
use Ps2alerts\Api\Contract\ConfigAwareTrait;
8
use Predis\Client;
9
use Ps2alerts\Api\Utility\RedisUtility;
10
11
class RedisServiceProvider extends AbstractServiceProvider implements
12
    ConfigAwareInterface
13
{
14
    use ConfigAwareTrait;
15
    /**
16
     * @var array
17
     */
18
    protected $provides = [
19
        'redis',
20
        'RedisUtility'
21
    ];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function register()
27
    {
28
        $this->getContainer()->add('redis', function () {
29
            $redisConfig = $this->getContainer()->get('config')['redis'];
30
31
            $args = [
32
                'host'     => $redisConfig['host'],
33
                'port'     => $redisConfig['port'],
34
                'database' => intval($redisConfig['db']),
35
                'scheme'   => 'tcp',
36
            ];
37
38
            if (! empty($redisConfig['pass'])) {
39
                $args['password'] = $redisConfig['pass'];
40
            }
41
42
            $client = new Client($args);
43
44
            return $client;
45
        });
46
47
        $this->getContainer()->share('RedisUtility', function() {
48
            return new RedisUtility();
49
        });
50
    }
51
}
52