Completed
Pull Request — master (#30)
by Alexander
09:17 queued 07:44
created

NullCache   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 72
ccs 0
cts 24
cp 0
rs 10
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A disableKeyNormalization() 0 2 1
A setKeyPrefix() 0 2 1
A enableKeyNormalization() 0 2 1
A clear() 0 3 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 iterableToArray() 0 3 2
A delete() 0 3 1
A getOrSet() 0 3 1
A getMultiple() 0 3 1
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
final class NullCache implements CacheInterface
15
{
16
    public function add($key, $value, $ttl = 0, Dependency $dependency = null): bool
17
    {
18
        return true;
19
    }
20
21
    public function deleteMultiple($keys): bool
22
    {
23
        return true;
24
    }
25
26
    public function set($key, $value, $ttl = null, Dependency $dependency = null): bool
27
    {
28
        return true;
29
    }
30
31
    public function get($key, $default = null)
32
    {
33
        return $default;
34
    }
35
36
    public function getMultiple($keys, $default = null): iterable
37
    {
38
        return array_fill_keys($this->iterableToArray($keys), $default);
39
    }
40
41
    public function setMultiple($values, $ttl = null, Dependency $dependency = null): bool
42
    {
43
        return true;
44
    }
45
46
    public function addMultiple(array $values, $ttl = null, Dependency $dependency = null): bool
47
    {
48
        return true;
49
    }
50
51
    public function getOrSet($key, callable $callable, $ttl = null, Dependency $dependency = null)
52
    {
53
        return $callable($this);
54
    }
55
56
    public function delete($key): bool
57
    {
58
        return true;
59
    }
60
61
    public function clear(): bool
62
    {
63
        return true;
64
    }
65
66
    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
    private function iterableToArray(iterable $iterable): array
84
    {
85
        return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable;
86
    }
87
}
88