MemcachedFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Mutex Library.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace AMF\Mutex\Storage\Memcached;
11
12
use AMF\Mutex\Storage\StorageFactoryInterface;
13
14
/**
15
 * Factory for creating a memcached instance.
16
 *
17
 * @author Amine Fattouch <[email protected]>
18
 */
19
class MemcachedFactory implements StorageFactoryInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $parameters = [
25
        [
26
            'host' => 'localhost',
27
            'port'  => 11211,
28
        ],
29
    ];
30
31
    /**
32
     * Constructor class.
33
     *
34
     * @param array $parameters
35
     */
36
    public function __construct(array $parameters = [])
37
    {
38
        $this->parameters = array_merge($this->parameters, $parameters);
39
    }
40
41
    /**
42
     * Creates an instance of memcached.
43
     *
44
     * @return \Memcached
45
     */
46
    public function create()
47
    {
48
        if (extension_loaded('memcached')) {
49
            $memcached = new \Memcached();
50
            $memcached->addServers($this->parameters);
51
52
            return $memcached;
53
        }
54
55
        throw new \RuntimeException(sprintf('Extension memcached is not loaded.'));
56
    }
57
}
58