Passed
Push — 6.x ( 08953e...092dd0 )
by Phil
13:02
created

FileCache::has()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
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