| Total Complexity | 14 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 |
||
| 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) |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | public function canSet($key, $value) |
||
| 69 | { |
||
| 70 | try { |
||
| 71 | return $this->validateKey($key) === $key; |
||
| 72 | } catch (CacheInvalidArgumentException $exception) { |
||
| 73 | return false; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | public function canDelete($key) |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.