Passed
Branch 5.x (508359)
by Phil
24:20
created

FileCache::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Route\Cache;
6
7
use Psr\SimpleCache\CacheInterface;
8
9
class FileCache implements CacheInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $cacheFilePath;
15
16
    /**
17
     * @var integer
18
     */
19
    protected $ttl;
20
21
    public function __construct(string $cacheFilePath, int $ttl)
22
    {
23
        $this->cacheFilePath = $cacheFilePath;
24
        $this->ttl = $ttl;
25
    }
26
27
    public function get($key, $default = null)
28
    {
29
        return ($this->has($key)) ? file_get_contents($this->cacheFilePath) : $default;
30
    }
31
32
    public function set($key, $value, $ttl = null): bool
33
    {
34
        return (bool) file_put_contents($this->cacheFilePath, $value);
35
    }
36
37
    public function has($key): bool
38
    {
39
        return file_exists($this->cacheFilePath) && time() - filemtime($this->cacheFilePath) < $this->ttl;
40
    }
41
42
    public function delete($key): bool
43
    {
44
        return unlink($this->cacheFilePath);
45
    }
46
47
    public function clear(): bool
48
    {
49
        return $this->delete($this->cacheFilePath);
50
    }
51
52
    public function getMultiple($keys, $default = null): iterable
53
    {
54
        return [];
55
    }
56
57
    public function setMultiple($values, $ttl = null): bool
58
    {
59
        return false;
60
    }
61
62
    public function deleteMultiple($keys): bool
63
    {
64
        return false;
65
    }
66
}
67