Lines 92.10% 35 / 38
Methods 76.92% 10 / 13
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 get 100.00% 2 / 2 100.00% 1 / 1 1
 set 100.00% 2 / 2 100.00% 1 / 1 1
 delete 100.00% 2 / 2 100.00% 1 / 1 1
 clear 100.00% 1 / 1 100.00% 1 / 1 1
 has 100.00% 2 / 2 100.00% 1 / 1 1
 [Lucent\Cache\Cache] setDefaultTtl 100.00% 1 / 1 100.00% 1 / 1 1
 [Lucent\Cache\Cache] getDefaultTtl 100.00% 1 / 1 100.00% 1 / 1 1
 [Lucent\Cache\Cache] resolveTtl 100.00% 1 / 1 100.00% 1 / 1 1
 [Lucent\Cache\Cache] validateKey 100.00% 2 / 2 100.00% 1 / 1 3
 [Lucent\Cache\Cache] expiryFromTtl 85.71% 6 / 7 0.00% 0 / 1 4.05
 [Lucent\Cache\Cache] getMultiple 100.00% 5 / 5 100.00% 1 / 1 2
 [Lucent\Cache\Cache] setMultiple 83.33% 5 / 6 0.00% 0 / 1 3.04
 [Lucent\Cache\Cache] deleteMultiple 83.33% 5 / 6 0.00% 0 / 1 3.04
17class NullDriver extends Cache
18{
19    /**
20     * @inheritDoc
21     */
22    public function get(string $key, mixed $default = null): mixed
23    {
24        $this->validateKey($key);
25
26        return $default;
27    }
28
29    /**
30     * @inheritDoc
31     */
32    public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
33    {
34        $this->validateKey($key);
35
36        return true;
37    }
38
39    /**
40     * @inheritDoc
41     */
42    public function delete(string $key): bool
43    {
44        $this->validateKey($key);
45
46        return true;
47    }
48
49    /**
50     * @inheritDoc
51     */
52    public function clear(): bool
53    {
54        return true;
55    }
56
57    /**
58     * @inheritDoc
59     */
60    public function has(string $key): bool
61    {
62        $this->validateKey($key);
63
64        return false;
65    }
66}

Inherited from Lucent\Cache\Cache

45    public function setDefaultTtl(?int $ttl): void
46    {
47        $this->defaultTtl = $ttl;
48    }
55    public function getDefaultTtl(): ?int
56    {
57        return $this->defaultTtl;
58    }
69    protected function resolveTtl(null|int|DateInterval $ttl): null|int|DateInterval
70    {
71        return $ttl ?? $this->defaultTtl;
72    }
89    protected function validateKey(mixed $key): void
90    {
91        if (!is_string($key) || preg_match('/^[A-Za-z0-9_.]{1,512}$/', $key) !== 1) {
92            throw new InvalidArgumentException($key);
93        }
94    }
102    protected function expiryFromTtl(null|int|DateInterval $ttl): ?int
103    {
104        if ($ttl === null) {
105            return null;
106        }
107
108        if ($ttl instanceof DateInterval) {
109            $ttl = (new \DateTimeImmutable())->add($ttl)->getTimestamp() - time();
110        }
111
112        if ($ttl <= 0) {
113            // Already expired: return a timestamp in the past so the item is
114            // treated as stale and removed rather than stored.
115            return time() - 1;
116        }
117
118        return time() + $ttl;
119    }
124    public function getMultiple(iterable $keys, mixed $default = null): iterable
125    {
126        $result = [];
127
128        foreach ($keys as $key) {
129            $this->validateKey($key);
130            $result[$key] = $this->get($key, $default);
131        }
132
133        return $result;
134    }
139    public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
140    {
141        $success = true;
142
143        foreach ($values as $key => $value) {
144            $this->validateKey($key);
145            if (!$this->set($key, $value, $ttl)) {
146                $success = false;
147            }
148        }
149
150        return $success;
151    }
156    public function deleteMultiple(iterable $keys): bool
157    {
158        $success = true;
159
160        foreach ($keys as $key) {
161            $this->validateKey($key);
162            if (!$this->delete($key)) {
163                $success = false;
164            }
165        }
166
167        return $success;
168    }