Completed
Push — 2.0 ( b5e900...ba9d42 )
by Marco
05:08
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

12 Methods

Rating   Name   Duplication   Size   Complexity  
getItem() 0 1 ?
getItems() 0 1 ?
hasItem() 0 1 ?
clear() 0 1 ?
deleteItem() 0 1 ?
deleteItems() 0 1 ?
save() 0 1 ?
saveDeferred() 0 1 ?
commit() 0 1 ?
A __construct() 0 5 1
A getLogger() 0 5 1
A setLogger() 7 7 2

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