Completed
Branch feature/pre-split (60f5c0)
by Anton
03:19
created

AbstractDriver::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 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\ActiveStoreInterface;
12
use Spiral\Cache\Prototypes\CacheStore;
13
14
/**
15
 * Common functionality for Memcache and Memcached drivers.
16
 */
17
abstract class AbstractDriver extends CacheStore implements DriverInterface, ActiveStoreInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $servers = [];
23
24
    /**
25
     * Default server options.
26
     *
27
     * @invisible
28
     *
29
     * @var array
30
     */
31
    protected $defaultServer = [
32
        'host'       => 'localhost',
33
        'port'       => 11211,
34
        'persistent' => true,
35
        'weight'     => 1,
36
    ];
37
38
    /**
39
     * @var \Memcached|\Memcache
40
     */
41
    protected $driver = null;
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 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...
47
    {
48
        foreach ($this->servers as $server) {
49
            //Merging default options
50
            $server = $server + $this->defaultServer;
51
52
            $this->driver->addServer(
53
                $server['host'],
54
                $server['port'],
55
                $server['weight']
56
            );
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function isAvailable(): bool
64
    {
65
        return true;
66
    }
67
}
68