Completed
Push — master ( 5c1276...fd0d63 )
by smiley
03:05
created
src/Drivers/SessionCacheDriver.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use chillerlan\SimpleCache\CacheException;
16 16
 use chillerlan\Settings\SettingsContainerInterface;
17 17
 
18
-class SessionCacheDriver extends CacheDriverAbstract{
18
+class SessionCacheDriver extends CacheDriverAbstract {
19 19
 
20 20
 	/**
21 21
 	 * @var string
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @throws \chillerlan\SimpleCache\CacheException
31 31
 	 */
32
-	public function __construct(SettingsContainerInterface $options = null){
32
+	public function __construct(SettingsContainerInterface $options = null) {
33 33
 		parent::__construct($options);
34 34
 
35 35
 		$this->key = $this->options->cacheSessionkey;
36 36
 
37
-		if(!is_string($this->key) || empty($this->key)){
37
+		if (!is_string($this->key) || empty($this->key)) {
38 38
 			$msg = 'invalid session cache key';
39 39
 
40 40
 			$this->logger->error($msg);
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 
48 48
 	/** @inheritdoc */
49
-	public function get(string $key, $default = null){
49
+	public function get(string $key, $default = null) {
50 50
 
51
-		if(isset($_SESSION[$this->key][$key])){
51
+		if (isset($_SESSION[$this->key][$key])) {
52 52
 
53
-			if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){
53
+			if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) {
54 54
 				return $_SESSION[$this->key][$key]['content'];
55 55
 			}
56 56
 
Please login to merge, or discard this patch.
src/Drivers/FileCacheDriver.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use chillerlan\Settings\SettingsContainerInterface;
17 17
 use FilesystemIterator, RecursiveDirectoryIterator, RecursiveIteratorIterator, stdClass;
18 18
 
19
-class FileCacheDriver extends CacheDriverAbstract{
19
+class FileCacheDriver extends CacheDriverAbstract {
20 20
 
21 21
 	/**
22 22
 	 * @var string
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @throws \chillerlan\SimpleCache\CacheException
32 32
 	 */
33
-	public function __construct(SettingsContainerInterface $options = null){
33
+	public function __construct(SettingsContainerInterface $options = null) {
34 34
 		parent::__construct($options);
35 35
 
36 36
 		$this->cachedir = rtrim($this->options->cacheFilestorage, '/\\').DIRECTORY_SEPARATOR;
37 37
 
38
-		if(!is_dir($this->cachedir)){
38
+		if (!is_dir($this->cachedir)) {
39 39
 			$msg = 'invalid cachedir "'.$this->cachedir.'"';
40 40
 
41 41
 			$this->logger->error($msg);
42 42
 			throw new CacheException($msg);
43 43
 		}
44 44
 
45
-		if(!is_writable($this->cachedir)){
45
+		if (!is_writable($this->cachedir)) {
46 46
 			$msg = 'cachedir is read-only. permissions?';
47 47
 
48 48
 			$this->logger->error($msg);
@@ -52,16 +52,16 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 
54 54
 	/** @inheritdoc */
55
-	public function get(string $key, $default = null){
55
+	public function get(string $key, $default = null) {
56 56
 		$filename = $this->getFilepath($key);
57 57
 
58
-		if(is_file($filename)){
58
+		if (is_file($filename)) {
59 59
 			$content = file_get_contents($filename);
60 60
 
61
-			if(!empty($content)){
61
+			if (!empty($content)) {
62 62
 				$data = unserialize($content);
63 63
 
64
-				if($data->ttl === null || $data->ttl > time()){
64
+				if ($data->ttl === null || $data->ttl > time()) {
65 65
 					return $data->content;
66 66
 				}
67 67
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		$file = $this->getFilepath($key);
79 79
 		$dir  = dirname($file);
80 80
 
81
-		if(!is_dir($dir)){
81
+		if (!is_dir($dir)) {
82 82
 			mkdir($dir, 0755, true);
83 83
 		}
84 84
 
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 		$data->ttl     = null;
87 87
 		$data->content = $value;
88 88
 
89
-		if($ttl !== null){
89
+		if ($ttl !== null) {
90 90
 			$data->ttl = time() + $ttl;
91 91
 		}
92 92
 
93 93
 		file_put_contents($file, serialize($data));
94 94
 
95
-		if(is_file($file)){
95
+		if (is_file($file)) {
96 96
 			return true;
97 97
 		}
98 98
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	public function delete(string $key):bool{
104 104
 		$filename = $this->getFilepath($key);
105 105
 
106
-		if(is_file($filename)){
106
+		if (is_file($filename)) {
107 107
 			return unlink($filename);
108 108
 		}
109 109
 
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
 
113 113
 	/** @inheritdoc */
114 114
 	public function clear():bool{
115
-		$iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS);
115
+		$iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS);
116 116
 		$return   = [];
117 117
 
118
-		foreach(new RecursiveIteratorIterator($iterator) as $path){
118
+		foreach (new RecursiveIteratorIterator($iterator) as $path) {
119 119
 
120 120
 			// skip files the parent directory - cache files are only under /a/ab/[hash]
121
-			if(strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false){
121
+			if (strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false) {
122 122
 				continue;
123 123
 			}
124 124
 
Please login to merge, or discard this patch.
src/Drivers/CacheDriverAbstract.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
31 31
 	 */
32
-	public function __construct(SettingsContainerInterface $options = null){
32
+	public function __construct(SettingsContainerInterface $options = null) {
33 33
 		$this->options = $options ?? new CacheOptions;
34 34
 		$this->logger  = new NullLogger; // logger will be set from the Cache instance
35 35
 	}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	public function getMultiple(array $keys, $default = null):array{
44 44
 		$data = [];
45 45
 
46
-		foreach($keys as $key){
46
+		foreach ($keys as $key) {
47 47
 			$data[$key] = $this->get($key, $default);
48 48
 		}
49 49
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	public function setMultiple(array $values, int $ttl = null):bool{
55 55
 		$return = [];
56 56
 
57
-		foreach($values as $key => $value){
57
+		foreach ($values as $key => $value) {
58 58
 			$return[] = $this->set($key, $value, $ttl);
59 59
 		}
60 60
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	public function deleteMultiple(array $keys):bool{
66 66
 		$return = [];
67 67
 
68
-		foreach($keys as $key){
68
+		foreach ($keys as $key) {
69 69
 			$return[] = $this->delete($key);
70 70
 		}
71 71
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	protected function checkReturn(array $booleans):bool{
81 81
 
82
-		foreach($booleans as $bool){
82
+		foreach ($booleans as $bool) {
83 83
 
84
-			if(!(bool)$bool){
84
+			if (!(bool)$bool) {
85 85
 				return false; // @codeCoverageIgnore
86 86
 			}
87 87
 
Please login to merge, or discard this patch.