DoctrineStorage::offsetGet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Storage\Model;
13
14
use Doctrine\Common\Cache\Cache;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class DoctrineStorage implements StorageInterface
20
{
21
    /**
22
     * @var Cache
23
     */
24
    private $cache;
25
26
    /**
27
     * @param Cache $cache
28
     */
29 6
    public function __construct(Cache $cache)
30
    {
31 6
        $this->cache = $cache;
32 6
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function offsetExists($offset)
38
    {
39 1
        return $this->cache->contains($offset);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 2
    public function offsetGet($offset)
46
    {
47 2
        if (($data = $this->cache->fetch($offset)) !== false) {
48 1
            return $data;
49
        }
50 1
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function offsetSet($offset, $value)
56
    {
57 1
        $this->cache->save($offset, $value);
58 1
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function offsetUnset($offset)
64
    {
65 1
        $this->cache->delete($offset);
66 1
    }
67
}
68