Completed
Push — master ( c4e3cd...c5cae6 )
by Anton
05:38
created

AbstractDriver::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Cache\Stores\Memcache;
10
11
use Spiral\Cache\CacheStore;
12
13
/**
14
 * Common functionality for Memcache and Memcached drivers.
15
 */
16
abstract class AbstractDriver extends CacheStore implements DriverInterface
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $servers = [];
22
23
    /**
24
     * Default server options.
25
     *
26
     * @invisible
27
     * @var array
28
     */
29
    protected $defaultServer = [
30
        'host'       => 'localhost',
31
        'port'       => 11211,
32
        'persistent' => true,
33
        'weight'     => 1
34
    ];
35
36
    /**
37
     * @var \Memcached|\Memcache
38
     */
39
    protected $driver = null;
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 View Code Duplication
    public function connect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        foreach ($this->servers as $server) {
47
            //Merging default options
48
            $server = $server + $this->defaultServer;
49
50
            $this->driver->addServer(
51
                $server['host'],
52
                $server['port'],
53
                $server['weight']
54
            );
55
        }
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function isAvailable()
62
    {
63
        return true;
64
    }
65
}