Completed
Pull Request — master (#30)
by Alexander
01:34
created

NullCache   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 76
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 17

16 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 3 1
A setSerializer() 0 2 1
A set() 0 3 1
A addMultiple() 0 3 1
A get() 0 3 1
A setMultiple() 0 3 1
A add() 0 3 1
A deleteMultiple() 0 3 1
A has() 0 3 1
A delete() 0 3 1
A disableKeyNormalization() 0 2 1
A setKeyPrefix() 0 2 1
A getOrSet() 0 3 1
A enableKeyNormalization() 0 2 1
A getMultiple() 0 3 1
A iterableToArray() 0 3 2
1
<?php
2
3
namespace Yiisoft\Cache;
4
5
use Yiisoft\Cache\Dependency\Dependency;
6
use Yiisoft\Cache\Serializer\SerializerInterface;
7
8
/**
9
 * NullCache does not cache anything reporting success for all methods calls.
10
 *
11
 * By replacing it with some other cache component, one can quickly switch from
12
 * non-caching mode to caching mode.
13
 */
14 1
final class NullCache implements CacheInterface
15
{
16 1
    public function add($key, $value, $ttl = 0, Dependency $dependency = null): bool
17
    {
18
        return true;
19 1
    }
20
21 1
    public function deleteMultiple($keys): bool
22
    {
23
        return true;
24 1
    }
25
26 1
    public function set($key, $value, $ttl = null, Dependency $dependency = null): bool
27
    {
28
        return true;
29 1
    }
30
31 1
    public function get($key, $default = null)
32
    {
33
        return $default;
34 1
    }
35
36 1
    public function getMultiple($keys, $default = null): iterable
37
    {
38
        return array_fill_keys($this->iterableToArray($keys), $default);
39 1
    }
40
41 1
    public function setMultiple($values, $ttl = null, Dependency $dependency = null): bool
42
    {
43
        return true;
44 1
    }
45
46 1
    public function addMultiple(array $values, $ttl = null, Dependency $dependency = null): bool
47
    {
48
        return true;
49 1
    }
50
51 1
    public function getOrSet($key, callable $callable, $ttl = null, Dependency $dependency = null)
52
    {
53
        return $callable($this);
54 1
    }
55
56 1
    public function delete($key): bool
57
    {
58
        return true;
59 1
    }
60
61 1
    public function clear(): bool
62
    {
63
        return true;
64 1
    }
65
66 1
    public function has($key): bool
67
    {
68
        return false;
69
    }
70
71
    public function enableKeyNormalization(): void
72
    {
73
    }
74
75
    public function disableKeyNormalization(): void
76
    {
77
    }
78
79
    public function setKeyPrefix(string $keyPrefix): void
80
    {
81
    }
82
83
    public function setSerializer(?SerializerInterface $serializer): void
84
    {
85
    }
86
87
    private function iterableToArray(iterable $iterable): array
88
    {
89
        return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable;
90
    }
91
}
92