Passed
Push — master ( f131ca...1ac6bf )
by Adrien
31:11 queued 19:36
created

SimpleCache3::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Collection\Memory;
4
5
use DateInterval;
6
use Psr\SimpleCache\CacheInterface;
7
8
/**
9
 * This is the default implementation for in-memory cell collection.
10
 *
11
 * Alternatives implementation should leverage off-memory, non-volatile storage
12
 * to reduce overall memory usage.
13
 */
14
class SimpleCache3 implements CacheInterface
15
{
16
    /**
17
     * @var array Cell Cache
18
     */
19
    private $cache = [];
20
21 1
    public function clear(): bool
22
    {
23 1
        $this->cache = [];
24
25 1
        return true;
26
    }
27
28
    /**
29
     * @param string $key
30
     */
31 8306
    public function delete($key): bool
32
    {
33 8306
        unset($this->cache[$key]);
34
35 8306
        return true;
36
    }
37
38
    /**
39
     * @param iterable $keys
40
     */
41 8396
    public function deleteMultiple($keys): bool
42
    {
43 8396
        foreach ($keys as $key) {
44 8273
            $this->delete($key);
45
        }
46
47 8396
        return true;
48
    }
49
50
    /**
51
     * @param string $key
52
     * @param mixed  $default
53
     */
54 7508
    public function get($key, $default = null): mixed
55
    {
56 7508
        if ($this->has($key)) {
57 7507
            return $this->cache[$key];
58
        }
59
60 2
        return $default;
61
    }
62
63
    /**
64
     * @param iterable $keys
65
     * @param mixed    $default
66
     */
67 1
    public function getMultiple($keys, $default = null): iterable
68
    {
69 1
        $results = [];
70 1
        foreach ($keys as $key) {
71 1
            $results[$key] = $this->get($key, $default);
72
        }
73
74 1
        return $results;
75
    }
76
77
    /**
78
     * @param string $key
79
     */
80 7508
    public function has($key): bool
81
    {
82 7508
        return array_key_exists($key, $this->cache);
83
    }
84
85
    /**
86
     * @param string                 $key
87
     * @param mixed                  $value
88
     * @param null|DateInterval|int $ttl
89
     */
90 8446
    public function set($key, $value, $ttl = null): bool
91
    {
92 8446
        $this->cache[$key] = $value;
93
94 8446
        return true;
95
    }
96
97
    /**
98
     * @param iterable               $values
99
     * @param null|DateInterval|int $ttl
100
     */
101 1
    public function setMultiple($values, $ttl = null): bool
102
    {
103 1
        foreach ($values as $key => $value) {
104 1
            $this->set($key, $value);
105
        }
106
107 1
        return true;
108
    }
109
}
110