Completed
Push — master ( 00fae0...ee941a )
by Dan
23:33 queued 15:03
created

AbstractCache   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A withCacheStorage() 0 6 1
A getCacheStorage() 0 4 1
1
<?php
2
/**
3
 * Src/Cache/AbstractCache.php
4
 *
5
 * @package     Ds\Cache
6
 * @subpackage  Cache
7
 * @author      Dan Smith <[email protected]>
8
 * @version     v.1 (20/03/2017)
9
 * @copyright   Copyright (c) 2017, Dan Smith
10
 */
11
namespace Ds\Cache;
12
13
use Ds\Cache\Storage\NullStorage;
14
15
/**
16
 * Abstract Cache Component
17
 *
18
 * @package Ds\Cache
19
 */
20
abstract class AbstractCache implements CacheInterface
21
{
22
23
    /**
24
     * @var CacheStorageInterface Cache Storage
25
     */
26
    protected $cache;
27
28
    /**
29
     * Creates a new instance of Cache with CacheStorageInterface.
30
     *
31
     * @param CacheStorageInterface|null $cacheStorage
32
     */
33 26
    public function __construct(CacheStorageInterface $cacheStorage = null)
34
    {
35 26
        $this->cache = $cacheStorage;
36
37 26
        if ($cacheStorage === null) {
38 1
            $this->cache = new NullStorage();
39
        }
40 26
    }
41
42
    /**
43
     * Create new instance with $CacheStorage
44
     *
45
     * @param  CacheStorageInterface $cacheStorage
46
     * @return CacheInterface
47
     */
48 1
    public function withCacheStorage(CacheStorageInterface $cacheStorage)
49
    {
50 1
        $new = clone $this;
51 1
        $new->cache = $cacheStorage;
52 1
        return $new;
53
    }
54
55
    /**
56
     * Get Cache Storage
57
     *
58
     * @return CacheStorageInterface
59
     */
60 4
    public function getCacheStorage()
61
    {
62 4
        return $this->cache;
63
    }
64
}
65