Passed
Branch master (0b4094)
by Alexander
01:32
created

NullCache   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

15 Methods

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