1 | <?php |
||
13 | class Redis implements ICache |
||
14 | { |
||
15 | use injector; |
||
16 | |||
17 | /** |
||
18 | * @var Container キャッシュ依存コンテナ |
||
19 | */ |
||
20 | private $cacheContainer; |
||
21 | |||
22 | /** |
||
23 | * @var string キャッシュ接頭辞 |
||
24 | */ |
||
25 | private $cachePrefix; |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | public function __construct(Container $cacheContainer) |
||
31 | { |
||
32 | $this->cacheContainer = $cacheContainer; |
||
33 | $this->cachePrefix = $this->cacheContainer->cachePrefix . '.' . $this->cacheContainer->classPrefix . '.'; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 4 | public function add($key, $value, $ttl = 0, $overwrite = false): bool |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 4 | public function get($key) |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 1 | public function delete($key): bool |
|
95 | { |
||
96 | 1 | if (!$this->isAvailableCacheLibrary()) { |
|
97 | return false; |
||
98 | } |
||
99 | |||
100 | 1 | if ($this->cacheContainer->driver->delete($key) > 0) { |
|
101 | 1 | $this->logger->info("Execute cache cleared: " . $key); |
|
102 | 1 | return true; |
|
103 | } else { |
||
104 | $this->logger->warn("Failed to clear cache: " . $key); |
||
105 | return false; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 1 | public function clear(): bool |
|
113 | { |
||
114 | 1 | if (!$this->isAvailableCacheLibrary()) { |
|
115 | return false; |
||
116 | } |
||
117 | |||
118 | 1 | $it = null; |
|
119 | 1 | $result = 1; |
|
120 | 1 | $this->cacheContainer->driver->setOption($this->cacheContainer->redisOptPrefix, ""); |
|
121 | 1 | while ($keys = $this->cacheContainer->driver->scan($it, "*")) { |
|
122 | 1 | $result *= $this->cacheContainer->driver->delete($keys); |
|
123 | } |
||
124 | 1 | $this->cacheContainer->driver->setOption($this->cacheContainer->redisOptPrefix, $this->cachePrefix); |
|
125 | |||
126 | 1 | if ($result > 0) { |
|
127 | 1 | $this->logger->info("Execute all cache cleared: " . $this->cachePrefix . "*"); |
|
128 | 1 | return true; |
|
129 | } else { |
||
130 | $this->logger->warn("Failed to clear all cache: " . $this->cachePrefix . "*"); |
||
131 | return false; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * キャッシュライブラリが使用可能か検査する |
||
137 | * @return bool 使用可能でtrue |
||
138 | */ |
||
139 | 4 | private function isAvailableCacheLibrary(): bool |
|
149 | } |
||
150 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.