Completed
Push — master ( 343e36...d95688 )
by smiley
02:47
created

CacheDriverAbstract::deleteMultiple()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class CacheDriverAbstract
4
 *
5
 * @filesource   CacheDriverAbstract.php
6
 * @created      25.05.2017
7
 * @package      chillerlan\SimpleCache\Drivers
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\SimpleCache\Drivers;
14
15
use chillerlan\SimpleCache\{CacheOptions};
16
use chillerlan\Traits\ImmutableSettingsInterface;
17
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, NullLogger};
18
19
abstract class CacheDriverAbstract implements CacheDriverInterface, LoggerAwareInterface{
20
	use LoggerAwareTrait;
21
22
	/**
23
	 * @var \chillerlan\SimpleCache\CacheOptions
24
	 */
25
	protected $options;
26
27
	/**
28
	 * CacheDriverAbstract constructor.
29
	 *
30
	 * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options
31
	 */
32
	public function __construct(ImmutableSettingsInterface $options = null){
33
		$this->options = $options ?? new CacheOptions;
34
		$this->logger  = new NullLogger; // logger will be set from the Cache instance
35
	}
36
37
	/** @inheritdoc */
38
	public function has(string $key):bool{
39
		return (bool)$this->get($key);
40
	}
41
42
	/** @inheritdoc */
43
	public function getMultiple(array $keys, $default = null):array{
44
		$data = [];
45
46
		foreach($keys as $key){
47
			$data[$key] = $this->get($key, $default);
48
		}
49
50
		return $data;
51
	}
52
53
	/** @inheritdoc */
54
	public function setMultiple(array $values, int $ttl = null):bool{
55
		$return = [];
56
57
		foreach($values as $key => $value){
58
			$return[] = $this->set($key, $value, $ttl);
59
		}
60
61
		return $this->checkReturn($return);
62
	}
63
64
	/** @inheritdoc */
65
	public function deleteMultiple(array $keys):bool{
66
		$return = [];
67
68
		foreach($keys as $key){
69
			$return[] = $this->delete($key);
70
		}
71
72
		return $this->checkReturn($return);
73
	}
74
75
	/**
76
	 * @param bool[] $booleans
77
	 *
78
	 * @return bool
79
	 */
80
	protected function checkReturn(array $booleans):bool{
81
82
		foreach($booleans as $bool){
83
84
			if(!(bool)$bool){
85
				return false; // @codeCoverageIgnore
86
			}
87
88
		}
89
90
		return true;
91
	}
92
93
}
94