Passed
Branch master (71c89b)
by Glynn
04:35
created
Category
src/Cache_Item.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
 	 * @param mixed $data
56 56
 	 * @param int $expiry
57 57
 	 */
58
-	public function __construct( string $key, $data, int $expiry ) {
58
+	public function __construct(string $key, $data, int $expiry) {
59 59
 		$this->key    = $key;
60 60
 		$this->data   = $data;
61 61
 		$this->expiry = $expiry;
Please login to merge, or discard this patch.
src/CacheInterface_Trait.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @return bool
34 34
 	 * @throws InvalidArgumentException
35 35
 	 */
36
-	protected function is_valid_key_value( $key ) : bool {
37
-		if ( ! \is_string( $key ) || empty( $key ) ) {
38
-			throw new \InvalidArgumentException( 'Key must be a valid string' );
36
+	protected function is_valid_key_value($key) : bool {
37
+		if ( ! \is_string($key) || empty($key)) {
38
+			throw new \InvalidArgumentException('Key must be a valid string');
39 39
 		}
40
-		return ! (bool) \preg_match( '|[\{\}\(\)/\\\@\:]|', $key );
40
+		return ! (bool) \preg_match('|[\{\}\(\)/\\\@\:]|', $key);
41 41
 	}
42 42
 
43 43
 	/**
@@ -46,20 +46,20 @@  discard block
 block discarded – undo
46 46
 	 * @param mixed $ttl
47 47
 	 * @return int
48 48
 	 */
49
-	public function ttl_to_seconds( $ttl ):int {
50
-		switch ( true ) {
51
-			case is_a( $ttl, DateInterval::class ):
52
-				$days  = (int) $ttl->format( '%a' );
53
-				$hours = (int) $ttl->format( '%h' );
54
-				$mins  = (int) $ttl->format( '%i' );
55
-				$secs  = (int) $ttl->format( '%s' );
49
+	public function ttl_to_seconds($ttl):int {
50
+		switch (true) {
51
+			case is_a($ttl, DateInterval::class):
52
+				$days  = (int) $ttl->format('%a');
53
+				$hours = (int) $ttl->format('%h');
54
+				$mins  = (int) $ttl->format('%i');
55
+				$secs  = (int) $ttl->format('%s');
56 56
 
57
-				return ( $days * 24 * 60 * 60 )
58
-					+ ( $hours * 60 * 60 )
59
-					+ ( $mins * 60 )
57
+				return ($days * 24 * 60 * 60)
58
+					+ ($hours * 60 * 60)
59
+					+ ($mins * 60)
60 60
 					+ $secs;
61 61
 
62
-			case is_numeric( $ttl ):
62
+			case is_numeric($ttl):
63 63
 				return (int) $ttl;
64 64
 
65 65
 			default:
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 	 * @param array<mixed> $array
74 74
 	 * @return bool
75 75
 	 */
76
-	protected function all_true( array $array ): bool {
77
-		foreach ( $array as $value ) {
78
-			if ( ! is_bool( $value ) ) {
76
+	protected function all_true(array $array): bool {
77
+		foreach ($array as $value) {
78
+			if ( ! is_bool($value)) {
79 79
 				return false;
80 80
 			}
81 81
 
82
-			if ( $value === false ) {
82
+			if ($value === false) {
83 83
 				return false;
84 84
 			}
85 85
 		}
Please login to merge, or discard this patch.
src/File_Cache.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 * @param string $filepath
69 69
 	 * @param string $extension
70 70
 	 */
71
-	public function __construct( string $filepath, string $extension = '.do' ) {
72
-		$this->filepath  = rtrim( $filepath, '\\/' );
71
+	public function __construct(string $filepath, string $extension = '.do') {
72
+		$this->filepath  = rtrim($filepath, '\\/');
73 73
 		$this->extension = $extension;
74 74
 
75 75
 		$this->set_wp_file_system();
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 	 * @return void
95 95
 	 */
96 96
 	protected function maybe_create_cache_dir(): void {
97
-		if ( ! $this->wp_filesystem->exists( $this->filepath ) ) {
98
-			$this->wp_filesystem->mkdir( $this->filepath );
97
+		if ( ! $this->wp_filesystem->exists($this->filepath)) {
98
+			$this->wp_filesystem->mkdir($this->filepath);
99 99
 		}
100 100
 	}
101 101
 
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	 * @return bool
107 107
 	 * @throws InvalidArgumentException
108 108
 	 */
109
-	public function has( $key ) {
110
-		if ( ! $this->is_valid_key_value( $key ) ) {
109
+	public function has($key) {
110
+		if ( ! $this->is_valid_key_value($key)) {
111 111
 			return false;
112 112
 		}
113
-		return ! is_null( $this->get( $key ) );
113
+		return ! is_null($this->get($key));
114 114
 	}
115 115
 
116 116
 	/**
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 	 * @return bool
124 124
 	 * @throws InvalidArgumentException
125 125
 	 */
126
-	public function set( $key, $value, $ttl = null ) {
127
-		if ( ! $this->is_valid_key_value( $key ) ) {
126
+	public function set($key, $value, $ttl = null) {
127
+		if ( ! $this->is_valid_key_value($key)) {
128 128
 			return false;
129 129
 		}
130 130
 
131 131
 		return $this->wp_filesystem->put_contents(
132
-			$this->compile_file_path( $key ),
133
-			serialize( $this->compile_cache_item( $key, $value, $ttl ) ) // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
132
+			$this->compile_file_path($key),
133
+			serialize($this->compile_cache_item($key, $value, $ttl)) // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
134 134
 		);
135 135
 	}
136 136
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @return mixed
143 143
 	 * @throws InvalidArgumentException
144 144
 	 */
145
-	public function get( $key, $default = null ) {
146
-		if ( ! $this->is_valid_key_value( $key ) ) {
145
+	public function get($key, $default = null) {
146
+		if ( ! $this->is_valid_key_value($key)) {
147 147
 			return $default;
148 148
 		}
149
-		$contents = $this->get_contents( $key );
149
+		$contents = $this->get_contents($key);
150 150
 		return $contents ? $contents->data : $default;
151 151
 	}
152 152
 
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
 	 * @return bool
158 158
 	 * @throws InvalidArgumentException
159 159
 	 */
160
-	public function delete( $key ) {
161
-		if ( ! $this->is_valid_key_value( $key ) ) {
160
+	public function delete($key) {
161
+		if ( ! $this->is_valid_key_value($key)) {
162 162
 			return false;
163 163
 		}
164 164
 		return $this->wp_filesystem->delete(
165
-			$this->compile_file_path( $key )
165
+			$this->compile_file_path($key)
166 166
 		);
167 167
 	}
168 168
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @return bool
173 173
 	 */
174 174
 	public function clear() {
175
-		return $this->wp_filesystem->delete( $this->filepath, true );
175
+		return $this->wp_filesystem->delete($this->filepath, true);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 	 * @param string|float|int|array<mixed>|object|resource|bool $default
183 183
 	 * @return array<string, mixed>
184 184
 	 */
185
-	public function getMultiple( $keys, $default = null ) {
185
+	public function getMultiple($keys, $default = null) {
186 186
 		return array_reduce(
187 187
 			$keys,
188
-			function( $carry, $key ) use ( $default ) {
189
-				$carry[ $key ] = $this->get( $key, $default );
188
+			function($carry, $key) use ($default) {
189
+				$carry[ $key ] = $this->get($key, $default);
190 190
 				return $carry;
191 191
 			},
192 192
 			array()
@@ -200,12 +200,12 @@  discard block
 block discarded – undo
200 200
 	 * @param int|null $ttl
201 201
 	 * @return bool
202 202
 	 */
203
-	public function setMultiple( $values, $ttl = null ) {
203
+	public function setMultiple($values, $ttl = null) {
204 204
 		return $this->all_true(
205 205
 			array_reduce(
206
-				array_keys( $values ),
207
-				function( $carry, $key ) use ( $values, $ttl ) {
208
-					$carry[ $key ] = $this->set( $key, $values[ $key ], $ttl );
206
+				array_keys($values),
207
+				function($carry, $key) use ($values, $ttl) {
208
+					$carry[ $key ] = $this->set($key, $values[ $key ], $ttl);
209 209
 					return $carry;
210 210
 				},
211 211
 				array()
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
 	 * @param array<int, string> $keys
220 220
 	 * @return bool
221 221
 	 */
222
-	public function deleteMultiple( $keys ) {
222
+	public function deleteMultiple($keys) {
223 223
 		return $this->all_true(
224 224
 			array_map(
225
-				function( $key ) {
226
-					return $this->delete( $key );
225
+				function($key) {
226
+					return $this->delete($key);
227 227
 				},
228 228
 				$keys
229 229
 			)
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 * @param string $filename;
238 238
 	 * @return string
239 239
 	 */
240
-	protected function compile_file_path( string $filename ): string {
240
+	protected function compile_file_path(string $filename): string {
241 241
 		return \wp_normalize_path(
242 242
 			sprintf(
243 243
 				'%s/%s%s',
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 * @param null|int|\DateInterval $ttl
257 257
 	 * @return Cache_Item
258 258
 	 */
259
-	protected function compile_cache_item( string $key, $data, $ttl ): Cache_Item {
259
+	protected function compile_cache_item(string $key, $data, $ttl): Cache_Item {
260 260
 		return new Cache_Item(
261 261
 			$key,
262 262
 			$data,
263
-			$this->compile_expiry( $this->ttl_to_seconds( $ttl ) )
263
+			$this->compile_expiry($this->ttl_to_seconds($ttl))
264 264
 		);
265 265
 	}
266 266
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @param int $expiry
271 271
 	 * @return int
272 272
 	 */
273
-	protected function compile_expiry( int $expiry ): int {
273
+	protected function compile_expiry(int $expiry): int {
274 274
 		return $expiry !== 0 ? $expiry + time() : 0;
275 275
 	}
276 276
 
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 	 * @param Cache_Item $data
284 284
 	 * @return bool
285 285
 	 */
286
-	protected function validate_contents( string $key, Cache_Item $data ): bool {
287
-		switch ( true ) {
286
+	protected function validate_contents(string $key, Cache_Item $data): bool {
287
+		switch (true) {
288 288
 			// Key passes doesnt match cache.
289 289
 			case $data->key !== $key:
290 290
 				return false;
291 291
 
292 292
 			// Expiry isnt numeric
293
-			case ! is_numeric( $data->expiry ):
293
+			case ! is_numeric($data->expiry):
294 294
 				return false;
295 295
 
296 296
 			// If expiry is 0 (Never expires), return true.
297
-			case intval( $data->expiry ) === 0:
297
+			case intval($data->expiry) === 0:
298 298
 				return true;
299 299
 
300 300
 			// If a timestamp, but expired.
301
-			case intval( $data->expiry ) < time():
301
+			case intval($data->expiry) < time():
302 302
 				return false;
303 303
 
304 304
 			default:
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 	 * @param string $key
313 313
 	 * @return Cache_Item|null If we have valid data (not expired), the data else null
314 314
 	 */
315
-	protected function get_contents( string $key ): ?Cache_Item {
315
+	protected function get_contents(string $key): ?Cache_Item {
316 316
 
317
-		$file_contents = $this->wp_filesystem->get_contents( $this->compile_file_path( $key ) ) ?: '';
317
+		$file_contents = $this->wp_filesystem->get_contents($this->compile_file_path($key)) ?: '';
318 318
 
319
-		$file_contents = \maybe_unserialize( $file_contents );
319
+		$file_contents = \maybe_unserialize($file_contents);
320 320
 
321
-		return is_a( $file_contents, Cache_Item::class ) && $this->validate_contents( $key, $file_contents )
321
+		return is_a($file_contents, Cache_Item::class) && $this->validate_contents($key, $file_contents)
322 322
 			? $file_contents
323 323
 			: null;
324 324
 	}
Please login to merge, or discard this patch.
src/Transient_Cache.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @param string|null $group
59 59
 	 */
60
-	public function __construct( ?string $group = null ) {
60
+	public function __construct(?string $group = null) {
61 61
 		$this->group = $group;
62 62
 	}
63 63
 
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * @return bool
72 72
 	 * @throws InvalidArgumentException
73 73
 	 */
74
-	public function set( $key, $value, $ttl = null ) {
75
-		if ( ! $this->is_valid_key_value( $key ) ) {
74
+	public function set($key, $value, $ttl = null) {
75
+		if ( ! $this->is_valid_key_value($key)) {
76 76
 			return false;
77 77
 		}
78 78
 		return \set_transient(
79
-			$this->parse_key( $key ),
79
+			$this->parse_key($key),
80 80
 			$value,
81
-			$this->ttl_to_seconds( $ttl )
81
+			$this->ttl_to_seconds($ttl)
82 82
 		);
83 83
 	}
84 84
 
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 * @return mixed
91 91
 	 * @throws InvalidArgumentException
92 92
 	 */
93
-	public function get( $key, $default = null ) {
94
-		if ( ! $this->is_valid_key_value( $key ) ) {
93
+	public function get($key, $default = null) {
94
+		if ( ! $this->is_valid_key_value($key)) {
95 95
 			return $default;
96 96
 		}
97
-		return \get_transient( $this->parse_key( $key ) ) ?: $default;
97
+		return \get_transient($this->parse_key($key)) ?: $default;
98 98
 	}
99 99
 
100 100
 	/**
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 	 * @return bool
105 105
 	 * @throws InvalidArgumentException
106 106
 	 */
107
-	public function delete( $key ) {
108
-		if ( ! $this->is_valid_key_value( $key ) ) {
107
+	public function delete($key) {
108
+		if ( ! $this->is_valid_key_value($key)) {
109 109
 			return false;
110 110
 		}
111
-		return \delete_transient( $this->parse_key( $key ) );
111
+		return \delete_transient($this->parse_key($key));
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function clear() {
120 120
 		$results = array_map(
121
-			function( $e ) {
122
-				return \delete_transient( $this->parse_key( $e ) );
121
+			function($e) {
122
+				return \delete_transient($this->parse_key($e));
123 123
 			},
124 124
 			$this->get_group_keys()
125 125
 		);
126
-		return ! \in_array( false, $results, true );
126
+		return ! \in_array(false, $results, true);
127 127
 	}
128 128
 
129 129
 	/**
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
 	 * @param mixed $default
134 134
 	 * @return array<string, mixed>
135 135
 	 */
136
-	public function getMultiple( $keys, $default = null ) {
136
+	public function getMultiple($keys, $default = null) {
137 137
 		return array_reduce(
138 138
 			$keys,
139
-			function( $carry, $key ) use ( $default ) {
140
-				$carry[ $key ] = $this->get( $key, $default );
139
+			function($carry, $key) use ($default) {
140
+				$carry[ $key ] = $this->get($key, $default);
141 141
 				return $carry;
142 142
 			},
143 143
 			array()
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
 	 * @param DateInterval|int|null $ttl
152 152
 	 * @return bool
153 153
 	 */
154
-	public function setMultiple( $values, $ttl = null ) {
154
+	public function setMultiple($values, $ttl = null) {
155 155
 		return $this->all_true(
156 156
 			array_reduce(
157
-				array_keys( $values ),
158
-				function( $carry, $key ) use ( $values, $ttl ) {
159
-					$carry[ $key ] = $this->set( $key, $values[ $key ], $ttl );
157
+				array_keys($values),
158
+				function($carry, $key) use ($values, $ttl) {
159
+					$carry[ $key ] = $this->set($key, $values[ $key ], $ttl);
160 160
 					return $carry;
161 161
 				},
162 162
 				array()
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 	 * @param array<int, string> $keys
171 171
 	 * @return bool
172 172
 	 */
173
-	public function deleteMultiple( $keys ) {
173
+	public function deleteMultiple($keys) {
174 174
 		return $this->all_true(
175 175
 			array_reduce(
176 176
 				$keys,
177
-				function( $carry, $key ) {
178
-					$carry[ $key ] = $this->delete( $key );
177
+				function($carry, $key) {
178
+					$carry[ $key ] = $this->delete($key);
179 179
 					return $carry;
180 180
 				},
181 181
 				array()
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	 * @param string $key
190 190
 	 * @return bool
191 191
 	 */
192
-	public function has( $key ) {
193
-		return ! is_null( $this->get( $key ) );
192
+	public function has($key) {
193
+		return ! is_null($this->get($key));
194 194
 	}
195 195
 
196 196
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 * @param string $key
200 200
 	 * @return string
201 201
 	 */
202
-	protected function parse_key( string $key ): string {
202
+	protected function parse_key(string $key): string {
203 203
 		return \sprintf(
204 204
 			'%s%s',
205 205
 			$this->group_key_prefix(),
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	protected function get_group_keys(): array {
227 227
 		// Extract the base cache keys (excluding pre/postfixes)
228 228
 		return array_map(
229
-			function( $key ) {
229
+			function($key) {
230 230
 				return \str_replace(
231 231
 					'_transient_' . $this->group_key_prefix(),
232 232
 					'',
Please login to merge, or discard this patch.