Passed
Push — master ( 380356...2e1f1e )
by Petr
10:45
created

Formatted::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_cache\Cache;
4
5
6
use kalanis\kw_cache\CacheException;
7
use kalanis\kw_cache\Interfaces;
8
9
10
/**
11
 * Class Formatted
12
 * @package kalanis\kw_cache\Cache
13
 * Caching content in any cache - another cache as semaphore for detection
14
 */
15
class Formatted
16
{
17
    /** @var Interfaces\ICache */
18
    protected $cache = null;
19
    /** @var Interfaces\IFormat */
20
    protected $format = null;
21
22 1
    public function __construct(Interfaces\ICache $cache, Interfaces\IFormat $format)
23
    {
24 1
        $this->cache = $cache;
25 1
        $this->format = $format;
26
    }
27
28
    /**
29
     * @param string $what
30
     * @throws CacheException
31
     */
32 1
    public function init(string $what): void
33
    {
34 1
        $this->cache->init($what);
35
    }
36
37
    /**
38
     * @throws CacheException
39
     * @return bool
40
     */
41 1
    public function exists(): bool
42
    {
43 1
        return $this->cache->exists();
44
    }
45
46
    /**
47
     * @param mixed $content
48
     * @throws CacheException
49
     * @return bool
50
     */
51 1
    public function set($content): bool
52
    {
53 1
        return $this->cache->set(strval($this->format->pack($content)));
54
    }
55
56
    /**
57
     * @throws CacheException
58
     * @return mixed
59
     */
60 1
    public function get()
61
    {
62 1
        return $this->exists() ? $this->format->unpack($this->cache->get()) : null;
63
    }
64
65
    /**
66
     * @throws CacheException
67
     */
68 1
    public function clear(): void
69
    {
70 1
        $this->cache->clear();
71
    }
72
}
73