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

AbstractDriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 26 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 50
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 13 13 2
A isAvailable() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}