Completed
Push — master ( 0f3db4...6e7c4d )
by Guillaume
16:16
created

StoreHandler::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Maikuro\DistributedConfigurationBundle\Handler;
4
5
use Maikuro\DistributedConfigurationBundle\Model\KeyValue;
6
use Webmozart\KeyValueStore\Api\KeyValueStore;
7
8
/**
9
 * Class StoreHandler.
10
 */
11
class StoreHandler
12
{
13
    /**
14
     * $store.
15
     *
16
     * @var KeyValueStore
17
     */
18
    private $store;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param KeyValueStore $store
24
     */
25
    public function __construct(KeyValueStore $store)
26
    {
27
        $this->store = $store;
28
    }
29
30
    /**
31
     * get.
32
     *
33
     * @param string $key
34
     * @throw Webmozart\KeyValueStore\Api\NoSuchKeyException
35
     *
36
     * @return KeyValue
37
     */
38
    public function get($key)
39
    {
40
        $value = $this->store->getOrFail($key);
41
42
        $keyValue = new KeyValue();
43
        $keyValue->setKey($key);
44
        $keyValue->setValue($value);
45
46
        return $keyValue;
47
    }
48
49
    /**
50
     * remove.
51
     *
52
     * @param string $key
53
     * @throw Webmozart\KeyValueStore\Api\WriteException
54
     */
55
    public function remove($key)
56
    {
57
        $this->store->remove($key);
58
    }
59
60
    /**
61
     * flush.
62
     *
63
     * @param KeyValue $keyValue
64
     *
65
     * @throws \Exception
66
     */
67
    public function flush(KeyValue $keyValue)
68
    {
69
        $this->store->set($keyValue->getKey(), $keyValue->getValue());
70
    }
71
}
72