DrupalCache   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 77
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doFetch() 0 8 2
A doContains() 0 4 1
A doSave() 0 10 2
A doDelete() 0 6 1
A doFlush() 0 6 1
A doGetStats() 0 4 1
1
<?php
2
3
namespace Drupal\controller_annotations\Cache;
4
5
use Doctrine\Common\Cache\CacheProvider;
6
use Drupal\Core\Cache\CacheBackendInterface;
7
8
class DrupalCache extends CacheProvider
9
{
10
    /**
11
     * @var CacheBackendInterface
12
     */
13
    private $cache;
14
15
    /**
16
     * @param CacheBackendInterface $cache
17
     */
18 13
    public function __construct(CacheBackendInterface $cache)
19
    {
20 13
        $this->cache = $cache;
21 13
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 11
    protected function doFetch($id)
27
    {
28 11
        if ($cache = $this->cache->get($id)) {
29 2
            return $cache->data;
30
        }
31
32 11
        return false;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38 1
    protected function doContains($id)
39
    {
40 1
        return $this->doFetch($id) !== false;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 8
    protected function doSave($id, $data, $lifeTime = 0)
47
    {
48 8
        if ($lifeTime === 0) {
49 8
            $this->cache->set($id, $data);
50
        } else {
51 1
            $this->cache->set($id, $data, time() + $lifeTime);
52
        }
53
54 8
        return true;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 1
    protected function doDelete($id)
61
    {
62 1
        $this->cache->delete($id);
63
64 1
        return true;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 1
    protected function doFlush()
71
    {
72 1
        $this->cache->deleteAll();
73
74 1
        return true;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 1
    protected function doGetStats()
81
    {
82 1
        return;
83
    }
84
}
85