AbstractCache   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 74
ccs 17
cts 17
cp 1
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrefix() 0 3 1
A deleteAll() 0 13 4
A setPrefix() 0 5 1
A setTtl() 0 5 1
A getTtl() 0 3 1
1
<?php
2
3
namespace TusPhp\Cache;
4
5
abstract class AbstractCache implements Cacheable
6
{
7
    /** @var int TTL in secs (default 1 day) */
8
    protected $ttl = 86400;
9
10
    /** @var string Prefix for cache keys */
11
    protected $prefix = 'tus:';
12
13
    /**
14
     * Set time to live.
15
     *
16
     * @param int $secs
17
     *
18
     * @return self
19
     */
20 3
    public function setTtl(int $secs) : self
21
    {
22 3
        $this->ttl = $secs;
23
24 3
        return $this;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 1
    public function getTtl() : int
31
    {
32 1
        return $this->ttl;
33
    }
34
35
    /**
36
     * Set cache prefix.
37
     *
38
     * @param string $prefix
39
     *
40
     * @return Cacheable
41
     */
42 5
    public function setPrefix(string $prefix) : Cacheable
43
    {
44 5
        $this->prefix = $prefix;
45
46 5
        return $this;
47
    }
48
49
    /**
50
     * Get cache prefix.
51
     *
52
     * @return string
53
     */
54 3
    public function getPrefix() : string
55
    {
56 3
        return $this->prefix;
57
    }
58
59
    /**
60
     * Delete all keys.
61
     *
62
     * @param array $keys
63
     *
64
     * @return bool
65
     */
66 3
    public function deleteAll(array $keys) : bool
67
    {
68 3
        if (empty($keys)) {
69 3
            return false;
70
        }
71
72 3
        $status = true;
73
74 3
        foreach ($keys as $key) {
75 3
            $status = $status && $this->delete($key);
76
        }
77
78 3
        return $status;
79
    }
80
}
81