Completed
Push — master ( b9da65...b16e40 )
by Marco
04:58
created

AbstractProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 11.86 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 7
loc 59
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getLogger() 0 5 1
A setLogger() 7 7 2
get() 0 1 ?
set() 0 1 ?
delete() 0 1 ?
clear() 0 1 ?
getMultiple() 0 1 ?
setMultiple() 0 1 ?
deleteMultiple() 0 1 ?
has() 0 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 namespace Comodojo\SimpleCache\Providers;
2
3
use \Comodojo\Foundation\Logging\Manager as LogManager;
4
use \Psr\SimpleCache\CacheInterface;
5
use \Psr\Log\LoggerInterface;
6
7
/**
8
 * Abstract provider implementation
9
 *
10
 * @package     Comodojo Spare Parts
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @license     MIT
13
 *
14
 * LICENSE:
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
abstract class AbstractProvider implements CacheInterface {
26
27
    /**
28
     * Current logger
29
     *
30
     * @var LoggerInterface
31
     */
32
    protected $logger;
33
34
    protected $driver;
35
36
    /**
37
     * Class constructor
38
     *
39
     * @throws \Comodojo\Exception\CacheException
40
     */
41 141
    public function __construct(LoggerInterface $logger = null) {
42
43 141
        $this->setLogger($logger);
44
45 141
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getLogger() {
51
52
        return $this->logger;
53
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 141 View Code Duplication
    public function setLogger(LoggerInterface $logger = null) {
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...
60
61 141
        $this->logger = is_null($logger) ? LogManager::create('cache', false)->getLogger() : $logger;
62
63 141
        return $this;
64
65
    }
66
67
    abstract public function get($key, $default = null);
68
69
    abstract public function set($key, $value, $ttl = null);
70
71
    abstract public function delete($key);
72
73
    abstract public function clear();
74
75
    abstract public function getMultiple($keys, $default = null);
76
77
    abstract public function setMultiple($values, $ttl = null);
78
79
    abstract public function deleteMultiple($keys);
80
81
    abstract public function has($key);
82
83
}
84