Completed
Pull Request — master (#13)
by Ankit
02:42
created

AbstractCache::getPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 2
    public function setTtl(int $secs)
19
    {
20 2
        $this->ttl = $secs;
21 2
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26 1
    public function getTtl() : int
27
    {
28 1
        return $this->ttl;
29
    }
30
31
    /**
32
     * Set cache prefix.
33
     *
34
     * @param string $prefix
35
     *
36
     * @return Cacheable
37
     */
38 2
    public function setPrefix(string $prefix) : Cacheable
39
    {
40 2
        $this->prefix = $prefix;
41
42 2
        return $this;
43
    }
44
45
    /**
46
     * Get cache prefix.
47
     *
48
     * @return string
49
     */
50 2
    public function getPrefix() : string
51
    {
52 2
        return $this->prefix;
53
    }
54
55
    /**
56
     * Delete all keys.
57
     *
58
     * @param array $keys
59
     *
60
     * @return bool
61
     */
62 2
    public function deleteAll(array $keys) : bool
63
    {
64 2
        if (empty($keys)) {
65 2
            return false;
66
        }
67
68 2
        $status = true;
69
70 2
        foreach ($keys as $key) {
71 2
            $status = $status && $this->delete($key);
72
        }
73
74 2
        return $status;
75
    }
76
}
77