Memcached   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getModuleName() 0 4 1
A create() 0 11 2
A isValidParams() 0 12 3
1
<?php
2
3
namespace Dafiti\Silex\Cache\Factory;
4
5
use Dafiti\Silex\Exception\InvalidCacheConfig;
6
7
class Memcached extends AbstractFactory
8
{
9
    const MODULE_NAME = 'memcached';
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
        $memcached = new \Memcached();
23
        $memcached->addServer($params['host'], $params['port']);
24
25
        return $memcached;
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