Formatted   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 10
c 0
b 0
f 0
dl 0
loc 54
ccs 15
cts 15
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 3 1
A set() 0 3 1
A clear() 0 3 1
A get() 0 3 2
A init() 0 3 1
A __construct() 0 4 1
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
    protected Interfaces\ICache $cache;
18
    protected Interfaces\IFormat $format;
19
20 1
    public function __construct(Interfaces\ICache $cache, Interfaces\IFormat $format)
21
    {
22 1
        $this->cache = $cache;
23 1
        $this->format = $format;
24 1
    }
25
26
    /**
27
     * @param string[] $what
28
     * @throws CacheException
29
     */
30 1
    public function init(array $what): void
31
    {
32 1
        $this->cache->init($what);
33 1
    }
34
35
    /**
36
     * @throws CacheException
37
     * @return bool
38
     */
39 1
    public function exists(): bool
40
    {
41 1
        return $this->cache->exists();
42
    }
43
44
    /**
45
     * @param mixed $content
46
     * @throws CacheException
47
     * @return bool
48
     */
49 1
    public function set($content): bool
50
    {
51 1
        return $this->cache->set(strval($this->format->pack($content)));
52
    }
53
54
    /**
55
     * @throws CacheException
56
     * @return mixed
57
     */
58 1
    public function get()
59
    {
60 1
        return $this->exists() ? $this->format->unpack($this->cache->get()) : null;
61
    }
62
63
    /**
64
     * @throws CacheException
65
     */
66 1
    public function clear(): void
67
    {
68 1
        $this->cache->clear();
69 1
    }
70
}
71