Passed
Push — drivers ( 5f8646...aadeb1 )
by Joe
01:53
created

CacheDriver::expired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Support\Cache;
4
5
use Psr\SimpleCache\CacheInterface;
6
use PhpWinTools\WmiScripting\Configuration\Config;
7
use PhpWinTools\WmiScripting\Exceptions\CacheInvalidArgumentException;
8
9
abstract class CacheDriver implements CacheInterface
10
{
11
    protected $config;
12
13
    protected $store;
14
15
    public function __construct(Config $config = null)
16
    {
17
        $this->config = $config ?? Config::instance();
18
    }
19
20
    /**
21
     * @param string $key
22
     *
23
     * @return bool
24
     *
25
     * @throws CacheInvalidArgumentException
26
     */
27
    abstract public function has($key);
28
29
30
    public function expired($key, $ttl = null): bool
0 ignored issues
show
Unused Code introduced by
The parameter $ttl is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function expired($key, /** @scrutinizer ignore-unused */ $ttl = null): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function expired(/** @scrutinizer ignore-unused */ $key, $ttl = null): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        return false;
33
    }
34
35
    public function valid($key, $ttl = null)
36
    {
37
        return $this->expired($key, $ttl) === false;
38
    }
39
40
    public function exists($key)
41
    {
42
        return $this->has($key);
43
    }
44
45
    public function doesNotExist($key)
46
    {
47
        return $this->exists($key) === false;
48
    }
49
50
    protected function validateKey($key)
51
    {
52
        if (is_string($key)) {
53
            return $key;
54
        }
55
56
        throw new CacheInvalidArgumentException("{$key} is not a valid key");
57
    }
58
59
    public function canGet($key)
60
    {
61
        try {
62
            return $this->has($key) || $this->valid($key);
63
        } catch (CacheInvalidArgumentException $exception) {
64
            return false;
65
        }
66
    }
67
68
    public function canSet($key, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    public function canSet($key, /** @scrutinizer ignore-unused */ $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        try {
71
            return $this->validateKey($key) === $key;
72
        } catch (CacheInvalidArgumentException $exception) {
73
            return false;
74
        }
75
    }
76
77
    public function canDelete($key)
78
    {
79
        try {
80
            return $this->has($key);
81
        } catch (CacheInvalidArgumentException $exception) {
82
            return false;
83
        }
84
    }
85
}
86