Skip to content

Commit 4aafbfe

Browse files
authored
Merge pull request #625 from Geolim4/master
More type hint & opcache optimizations
2 parents 6969fa2 + 3e8452b commit 4aafbfe

File tree

13 files changed

+92
-91
lines changed

13 files changed

+92
-91
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ What types of changes does your code introduce to Phpfastcache?
99
_Put an `x` in the boxes that apply_
1010

1111
- [ ] Bugfix (non-breaking change which fixes an issue)
12+
- [ ] Improvement (non-breaking change which improves an existing code/behavior)
1213
- [ ] Deprecated third party dependency update
1314
- [ ] New feature (non-breaking change which adds functionality)
1415
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

docs/migration/MigratingFromV6ToV7.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ The method still returns a valid string but its format has changed slightly.
158158
### Couchbase PHP SDK
159159
The Couchbase driver has been updated to works with PHP SDK 2.4+ (Couchbase Server 5+).
160160
Therefore it way requires a Couchbase Server updated combined with an SDK update.
161-
161+
162162
### Constants autoload-related
163-
As of the V7, all the constant starting by _PFC\_*_ were moved into the `Phpfastcache\Autoload` namespace\
163+
As of the V7, all the constant starting by _PFC\_*_ were moved in to the `Phpfastcache\Autoload` namespace\
164164
to not pollute php's root namespace.
165165

166166
### Autoload mechanism

lib/Phpfastcache/CacheManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected static function getFallbackInstance(string $driver, ConfigurationOptio
165165
$fallback = $config->getFallback();
166166
$config->setFallback('');
167167
\trigger_error(\sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver,
168-
$fallback), E_USER_WARNING);
168+
$fallback), \E_USER_WARNING);
169169
return self::getInstance($fallback, $config->getFallbackConfig());
170170
} catch (PhpfastcacheInvalidArgumentException $e) {
171171
throw new PhpfastcacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
@@ -328,7 +328,7 @@ public static function getDefaultConfig(): ConfigurationOption
328328
public static function getStaticSystemDrivers(): array
329329
{
330330
\trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.',
331-
__METHOD__), E_USER_DEPRECATED);
331+
__METHOD__), \E_USER_DEPRECATED);
332332
return [
333333
'Apc',
334334
'Apcu',
@@ -361,7 +361,7 @@ public static function getStaticSystemDrivers(): array
361361
public static function getStaticAllDrivers(): array
362362
{
363363
\trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.',
364-
__METHOD__), E_USER_DEPRECATED);
364+
__METHOD__), \E_USER_DEPRECATED);
365365
return \array_merge(self::getStaticSystemDrivers(), [
366366
'Devtrue',
367367
'Devfalse',

lib/Phpfastcache/Config/ConfigurationOption.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,25 @@ public function __construct(...$args)
110110
* Detect unwanted keys and throw an exception.
111111
* No more kidding now, it's 21th century.
112112
*/
113-
if (array_diff_key($array, get_object_vars($this))) {
113+
if (\array_diff_key($array, \get_object_vars($this))) {
114114
throw new PhpfastcacheInvalidConfigurationException(\sprintf(
115115
'Invalid option(s) for the config %s: %s',
116116
static::class,
117-
implode(', ', array_keys(array_diff_key($array, get_object_vars($this))))
117+
\implode(', ', \array_keys(\array_diff_key($array, \get_object_vars($this))))
118118
));
119119
}
120120

121-
foreach (get_object_vars($this) as $property => $value) {
121+
foreach (\get_object_vars($this) as $property => $value) {
122122

123-
if (array_key_exists($property, $array)) {
123+
if (\array_key_exists($property, $array)) {
124124
$this->$property = &$array[$property];
125125
} else {
126126
$array[$property] = &$this->$property;
127127
}
128128
}
129129

130-
foreach (get_class_methods($this) as $method) {
131-
if (strpos($method, 'set') === 0) {
130+
foreach (\get_class_methods($this) as $method) {
131+
if (\strpos($method, 'set') === 0) {
132132
$value = null;
133133
try {
134134
/**
@@ -137,7 +137,7 @@ public function __construct(...$args)
137137
* to allow us to retrieve the value
138138
* in catch statement bloc
139139
*/
140-
$value = $this->{lcfirst(substr($method, 3))};
140+
$value = $this->{\lcfirst(\substr($method, 3))};
141141
$this->{$method}($value);
142142
} catch (\TypeError $e) {
143143
$typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value);
@@ -147,7 +147,7 @@ public function __construct(...$args)
147147

148148
throw new PhpfastcacheInvalidConfigurationException(\sprintf(
149149
'Invalid type hint found for "%s", expected "%s" got "%s"',
150-
lcfirst(substr($method, 3)),
150+
\lcfirst(\substr($method, 3)),
151151
$typeHintExpected,
152152
$typeHintGot
153153
));
@@ -163,7 +163,7 @@ public function __construct(...$args)
163163
*/
164164
public function getOption(string $optionName)
165165
{
166-
\trigger_error(\sprintf('Method "%s" is deprecated, use "getOptionName()" instead', __METHOD__), E_USER_DEPRECATED);
166+
\trigger_error(\sprintf('Method "%s" is deprecated, use "getOptionName()" instead', __METHOD__), \E_USER_DEPRECATED);
167167
return $this->$optionName ?? null;
168168
}
169169

@@ -173,7 +173,7 @@ public function getOption(string $optionName)
173173
*/
174174
public function isValidOption(string $optionName)
175175
{
176-
return property_exists($this, $optionName);
176+
return \property_exists($this, $optionName);
177177
}
178178

179179
/**
@@ -229,7 +229,7 @@ public function isIgnoreSymfonyNotice(): bool
229229
public function setIgnoreSymfonyNotice(bool $ignoreSymfonyNotice): self
230230
{
231231
if ($ignoreSymfonyNotice) {
232-
\trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', E_USER_DEPRECATED);
232+
\trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', \E_USER_DEPRECATED);
233233
}
234234
$this->ignoreSymfonyNotice = $ignoreSymfonyNotice;
235235
return $this;

lib/Phpfastcache/Core/Item/ItemExtendedTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public function getTagsAsString($separator = ', '): string
382382
*/
383383
public function removeTag($tagName): ExtendedCacheItemInterface
384384
{
385-
if (($key = \array_search($tagName, $this->tags)) !== false) {
385+
if (($key = \array_search($tagName, $this->tags, true)) !== false) {
386386
unset($this->tags[$key]);
387387
$this->removedTags[] = $tagName;
388388
}

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public function saveDeferred(CacheItemInterface $item)
395395
}
396396

397397
/**
398-
* @return mixed|null
398+
* @return bool
399399
* @throws PhpfastcacheInvalidArgumentException
400400
*/
401401
public function commit()
@@ -416,6 +416,6 @@ public function commit()
416416
}
417417
}
418418

419-
return (bool)$return;
419+
return (bool) $return;
420420
}
421421
}

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function getInstanceId(): string
242242
* @return bool
243243
* @throws PhpfastcacheLogicException
244244
*/
245-
public function driverWriteTags(ExtendedCacheItemInterface $item)
245+
public function driverWriteTags(ExtendedCacheItemInterface $item): bool
246246
{
247247
/**
248248
* Do not attempt to write tags
@@ -322,7 +322,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
322322
* @param $key
323323
* @return string
324324
*/
325-
public function getTagKey($key)
325+
public function getTagKey($key):string
326326
{
327327
return self::DRIVER_TAGS_KEY_PREFIX . $key;
328328
}

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function getHelp(): string;
181181
* key is not found. However, if no keys are specified then an empty
182182
* traversable MUST be returned instead.
183183
*/
184-
public function getItemsByTag($tagName);
184+
public function getItemsByTag($tagName): array;
185185

186186
/**
187187
* Returns a traversable set of cache items by one of multiple tag names.
@@ -199,7 +199,7 @@ public function getItemsByTag($tagName);
199199
* key is not found. However, if no keys are specified then an empty
200200
* traversable MUST be returned instead.
201201
*/
202-
public function getItemsByTags(array $tagNames);
202+
public function getItemsByTags(array $tagNames): array;
203203

204204
/**
205205
* Returns a traversable set of cache items by all of multiple tag names.
@@ -217,7 +217,7 @@ public function getItemsByTags(array $tagNames);
217217
* key is not found. However, if no keys are specified then an empty
218218
* traversable MUST be returned instead.
219219
*/
220-
public function getItemsByTagsAll(array $tagNames);
220+
public function getItemsByTagsAll(array $tagNames): array;
221221

222222
/**
223223
* Returns A json string that represents an array of items by tags-based.
@@ -233,7 +233,7 @@ public function getItemsByTagsAll(array $tagNames);
233233
*
234234
* @return string
235235
*/
236-
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512);
236+
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512): string;
237237

238238
/**
239239
* Removes the item from the pool by tag.
@@ -248,7 +248,7 @@ public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth
248248
* @return bool
249249
* True if the item was successfully removed. False if there was an error.
250250
*/
251-
public function deleteItemsByTag($tagName);
251+
public function deleteItemsByTag($tagName): bool;
252252

253253
/**
254254
* Removes the item from the pool by one of multiple tag names.
@@ -263,7 +263,7 @@ public function deleteItemsByTag($tagName);
263263
* @return bool
264264
* True if the items were successfully removed. False if there was an error.
265265
*/
266-
public function deleteItemsByTags(array $tagNames);
266+
public function deleteItemsByTags(array $tagNames): bool;
267267

268268
/**
269269
* Removes the item from the pool by all of multiple tag names.
@@ -278,7 +278,7 @@ public function deleteItemsByTags(array $tagNames);
278278
* @return bool
279279
* True if the items were successfully removed. False if there was an error.
280280
*/
281-
public function deleteItemsByTagsAll(array $tagNames);
281+
public function deleteItemsByTagsAll(array $tagNames): bool;
282282

283283
/**
284284
* Increment the items from the pool by tag.
@@ -295,7 +295,7 @@ public function deleteItemsByTagsAll(array $tagNames);
295295
* @return bool
296296
* True if the item was successfully incremented. False if there was an error.
297297
*/
298-
public function incrementItemsByTag($tagName, $step = 1);
298+
public function incrementItemsByTag($tagName, $step = 1): bool;
299299

300300
/**
301301
* Increment the items from the pool by one of multiple tag names.
@@ -312,7 +312,7 @@ public function incrementItemsByTag($tagName, $step = 1);
312312
* @return bool
313313
* True if the items were successfully incremented. False if there was an error.
314314
*/
315-
public function incrementItemsByTags(array $tagNames, $step = 1);
315+
public function incrementItemsByTags(array $tagNames, $step = 1): bool;
316316

317317
/**
318318
* Increment the items from the pool by all of multiple tag names.
@@ -329,7 +329,7 @@ public function incrementItemsByTags(array $tagNames, $step = 1);
329329
* @return bool
330330
* True if the items were successfully incremented. False if there was an error.
331331
*/
332-
public function incrementItemsByTagsAll(array $tagNames, $step = 1);
332+
public function incrementItemsByTagsAll(array $tagNames, $step = 1): bool;
333333

334334
/**
335335
* Decrement the items from the pool by tag.
@@ -346,7 +346,7 @@ public function incrementItemsByTagsAll(array $tagNames, $step = 1);
346346
* @return bool
347347
* True if the item was successfully decremented. False if there was an error.
348348
*/
349-
public function decrementItemsByTag($tagName, $step = 1);
349+
public function decrementItemsByTag($tagName, $step = 1): bool;
350350

351351
/**
352352
* Decrement the items from the pool by one of multiple tag names.
@@ -363,7 +363,7 @@ public function decrementItemsByTag($tagName, $step = 1);
363363
* @return bool
364364
* True if the item was successfully decremented. False if there was an error.
365365
*/
366-
public function decrementItemsByTags(array $tagNames, $step = 1);
366+
public function decrementItemsByTags(array $tagNames, $step = 1): bool;
367367

368368
/**
369369
* Decrement the items from the pool by all of multiple tag names.
@@ -380,7 +380,7 @@ public function decrementItemsByTags(array $tagNames, $step = 1);
380380
* @return bool
381381
* True if the items were successfully decremented. False if there was an error.
382382
*/
383-
public function decrementItemsByTagsAll(array $tagNames, $step = 1);
383+
public function decrementItemsByTagsAll(array $tagNames, $step = 1): bool;
384384

385385
/**
386386
* Decrement the items from the pool by tag.
@@ -397,7 +397,7 @@ public function decrementItemsByTagsAll(array $tagNames, $step = 1);
397397
* @return bool
398398
* True if the item was successfully appended. False if there was an error.
399399
*/
400-
public function appendItemsByTag($tagName, $data);
400+
public function appendItemsByTag($tagName, $data): bool;
401401

402402
/**
403403
* Append the items from the pool by one of multiple tag names.
@@ -414,7 +414,7 @@ public function appendItemsByTag($tagName, $data);
414414
* @return bool
415415
* True if the items were successfully appended. False if there was an error.
416416
*/
417-
public function appendItemsByTags(array $tagNames, $data);
417+
public function appendItemsByTags(array $tagNames, $data): bool;
418418

419419
/**
420420
* Append the items from the pool by all of multiple tag names.
@@ -431,7 +431,7 @@ public function appendItemsByTags(array $tagNames, $data);
431431
* @return bool
432432
* True if the items were successfully appended. False if there was an error.
433433
*/
434-
public function appendItemsByTagsAll(array $tagNames, $data);
434+
public function appendItemsByTagsAll(array $tagNames, $data): bool;
435435

436436
/**
437437
* Prepend the items from the pool by tag.
@@ -448,7 +448,7 @@ public function appendItemsByTagsAll(array $tagNames, $data);
448448
* @return bool
449449
* True if the item was successfully prepended. False if there was an error.
450450
*/
451-
public function prependItemsByTag($tagName, $data);
451+
public function prependItemsByTag($tagName, $data): bool;
452452

453453
/**
454454
* Prepend the items from the pool by one of multiple tag names.
@@ -465,7 +465,7 @@ public function prependItemsByTag($tagName, $data);
465465
* @return bool
466466
* True if the item was successfully prepended. False if there was an error.
467467
*/
468-
public function prependItemsByTags(array $tagNames, $data);
468+
public function prependItemsByTags(array $tagNames, $data): bool;
469469

470470
/**
471471
* Prepend the items from the pool by all of multiple tag names.
@@ -482,7 +482,7 @@ public function prependItemsByTags(array $tagNames, $data);
482482
* @return bool
483483
* True if the items were successfully prepended. False if there was an error.
484484
*/
485-
public function prependItemsByTagsAll(array $tagNames, $data);
485+
public function prependItemsByTagsAll(array $tagNames, $data): bool;
486486

487487
/**
488488
* @param \Psr\Cache\CacheItemInterface $item

0 commit comments

Comments
 (0)