DoctrineCacheSequenceNumberStore::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
namespace Kaliop\Queueing\Plugins\KinesisBundle\Service;
4
5
use Doctrine\Common\Cache\Cache;
6
7
/**
8
 * Uses the Doctrine Cache to store the Sequence Number of stream shards
9
 */
10
class DoctrineCacheSequenceNumberStore implements SequenceNumberStoreInterface
11
{
12
    /** @var  \Doctrine\Common\Cache\Cache */
13
    protected $cache;
14
15 1
    public function __construct(Cache $cacheService)
16
    {
17 1
        $this->cache =  $cacheService;
18 1
    }
19
20
    /**
21
     * @param $stream
22
     * @param $shard
23
     * @param $sequenceNumber
24
     */
25
    public function save($stream, $shard, $sequenceNumber)
26
    {
27
        $this->cache->save($this->getCacheId($stream, $shard), $sequenceNumber);
28
    }
29
30
    /**
31
     * @param $stream
32
     * @param $shard
33
     * @return string|null
34
     */
35
    public function fetch($stream, $shard)
36
    {
37
        return $this->cache->fetch($this->getCacheId($stream, $shard));
38
    }
39
40
    protected function getCacheId($stream, $shard)
41
    {
42
        return md5(md5($stream).md5($shard));
43
    }
44
}