Redis::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 6
nop 1
1
<?php
2
3
namespace Dafiti\Silex\Cache\Factory;
4
5
use Dafiti\Silex\Exception\InvalidCacheConfig;
6
7
class Redis extends AbstractFactory
8
{
9
    const MODULE_NAME = 'redis';
10
11
    public function getModuleName()
12
    {
13
        return self::MODULE_NAME;
14
    }
15
16
    public function create(array $params)
17
    {
18
        if (!$this->isValidParams($params)) {
19
            throw new InvalidCacheConfig();
20
        }
21
22
        $redis = new \Redis();
23
        $redis->connect($params['host'], $params['port']);
24
25
        return $redis;
26
    }
27
28
    /**
29
     * @param array $params
30
     *
31
     * @return bool
32
     */
33
    private function isValidParams(array $params)
34
    {
35
        if (!isset($params['host'])) {
36
            return false;
37
        }
38
39
        if (!isset($params['port'])) {
40
            return false;
41
        }
42
43
        return true;
44
    }
45
}
46