Memcache::isValidParams()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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