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

AbstractCache::withCacheStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 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