Completed
Push — master ( b45a00...0b0210 )
by Patryk
04:17
created

DoctrineCacheBridge   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 2
A has() 0 4 1
A save() 0 4 1
A delete() 0 4 1
A deleteAll() 0 8 2
1
<?php
2
3
namespace KaLLoSz\Twig\Extension\Cache;
4
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\Common\Cache\ClearableCache;
7
8
/**
9
 * Class DoctrineCacheBridge
10
 */
11
class DoctrineCacheBridge implements CacheInterface
12
{
13
    /**
14
     * @var Cache
15
     */
16
    private $cache;
17
18
    /**
19
     * @param Cache $cache
20
     */
21 28
    public function __construct(Cache $cache)
22
    {
23 28
        $this->cache = $cache;
24 28
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 4
    public function get($id)
30
    {
31 4
        return $this->has($id) ? $this->cache->fetch($id) : false;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 20
    public function has($id)
38
    {
39 20
        return $this->cache->contains($id);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 20
    public function save($id, $data, $lifeTime = 0)
46
    {
47 20
        return $this->cache->save($id, $data, $lifeTime);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 4
    public function delete($id)
54
    {
55 4
        return $this->cache->delete($id);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 8
    public function deleteAll()
62
    {
63 8
        if ($this->cache instanceof ClearableCache) {
64 4
            return $this->cache->deleteAll();
65
        }
66
67 4
        return false;
68
    }
69
}
70