FileCache   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 9
c 1
b 0
f 0
dl 0
loc 44
ccs 8
cts 18
cp 0.4444
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getMultiple() 0 3 1
A __construct() 0 2 1
A delete() 0 3 1
A get() 0 3 2
A deleteMultiple() 0 3 1
A has() 0 3 2
A set() 0 3 1
A setMultiple() 0 3 1
A clear() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Route\Cache;
6
7
use Psr\SimpleCache\{CacheInterface, InvalidArgumentException};
8
9
class FileCache implements CacheInterface
10
{
11 3
    public function __construct(protected string $cacheFilePath, protected int $ttl)
12
    {
13 3
    }
14
15 3
    public function get(string $key, mixed $default = null): mixed
16
    {
17 3
        return ($this->has($key)) ? file_get_contents($this->cacheFilePath) : $default;
18
    }
19
20 3
    public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
21
    {
22 3
        return (bool) file_put_contents($this->cacheFilePath, $value);
23
    }
24
25 3
    public function has(string $key): bool
26
    {
27 3
        return file_exists($this->cacheFilePath) && time() - filemtime($this->cacheFilePath) < $this->ttl;
28
    }
29
30
    public function delete(string $key): bool
31
    {
32
        return unlink($this->cacheFilePath);
33
    }
34
35
    public function clear(): bool
36
    {
37
        return $this->delete($this->cacheFilePath);
38
    }
39
40
    public function getMultiple(iterable $keys, mixed $default = null): iterable
41
    {
42
        return [];
43
    }
44
45
    public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
46
    {
47
        return false;
48
    }
49
50
    public function deleteMultiple(iterable $keys): bool
51
    {
52
        return false;
53
    }
54
}
55