Skip to content

Commit d6f9160

Browse files
committed
Added Opcache improvements by namespacing php core's functions
1 parent 289656f commit d6f9160

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+228
-228
lines changed

src/autoload.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,42 @@
2020
* Register Autoload
2121
*/
2222
spl_autoload_register(function ($entity) {
23-
$module = explode('\\', $entity, 2);
24-
if (!in_array($module[ 0 ], ['phpFastCache', 'Psr'])) {
23+
$module = \explode('\\', $entity, 2);
24+
if (!\in_array($module[ 0 ], ['phpFastCache', 'Psr'])) {
2525
/**
2626
* Not a part of phpFastCache file
2727
* then we return here.
2828
*/
2929
return;
30-
} else if (strpos($entity, 'Psr\Cache') === 0) {
31-
$path = PFC_BIN_DIR . 'legacy/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
30+
} else if (\strpos($entity, 'Psr\Cache') === 0) {
31+
$path = PFC_BIN_DIR . 'legacy/Psr/Cache/src/' . \substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
3232

33-
if (is_readable($path)) {
33+
if (\is_readable($path)) {
3434
require_once $path;
3535
} else {
3636
trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
3737
}
3838
return;
39-
} else if (strpos($entity, 'Psr\SimpleCache') === 0) {
40-
$path = PFC_BIN_DIR . 'legacy/Psr/SimpleCache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
39+
} else if (\strpos($entity, 'Psr\SimpleCache') === 0) {
40+
$path = PFC_BIN_DIR . 'legacy/Psr/SimpleCache/src/' . \substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
4141

42-
if (is_readable($path)) {
42+
if (\is_readable($path)) {
4343
require_once $path;
4444
} else {
4545
trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR);
4646
}
4747
return;
4848
}
4949

50-
$entity = str_replace('\\', '/', $entity);
50+
$entity = \str_replace('\\', '/', $entity);
5151
$path = __DIR__ . '/' . $entity . '.' . PFC_PHP_EXT;
5252

53-
if (is_readable($path)) {
53+
if (\is_readable($path)) {
5454
require_once $path;
5555
}
5656
});
5757

58-
if ((!defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists('Composer\Autoload\ClassLoader')) {
58+
if ((!\defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists('Composer\Autoload\ClassLoader')) {
5959
trigger_error('Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
6060
E_USER_WARNING);
6161
}

src/phpFastCache/Api.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public static function getPhpFastCacheVersion($fallbackOnChangelog = true, $cach
6868
return $version;
6969
}
7070

71-
if(function_exists('shell_exec')){
71+
if(\function_exists('shell_exec')){
7272
$stdout = shell_exec('git describe --abbrev=0 --tags');
73-
if(is_string($stdout)){
74-
$version = trim($stdout);
73+
if(\is_string($stdout)){
74+
$version = \trim($stdout);
7575
return $version;
7676
}
7777
throw new phpFastCacheLogicException('The git command used to retrieve the PhpFastCache version has failed.');
@@ -82,12 +82,12 @@ public static function getPhpFastCacheVersion($fallbackOnChangelog = true, $cach
8282
}
8383

8484
$changelogFilename = __DIR__ . '/../../CHANGELOG.md';
85-
if(file_exists($changelogFilename)){
85+
if(\file_exists($changelogFilename)){
8686
$versionPrefix = '## ';
87-
$changelog = explode("\n", self::getPhpFastCacheChangelog());
87+
$changelog = \explode("\n", self::getPhpFastCacheChangelog());
8888
foreach ($changelog as $line){
89-
if(strpos($line, $versionPrefix) === 0){
90-
$version = trim(str_replace($versionPrefix, '', $line));
89+
if(\strpos($line, $versionPrefix) === 0){
90+
$version = \trim(\str_replace($versionPrefix, '', $line));
9191
return $version;
9292
}
9393
}
@@ -108,10 +108,10 @@ public static function getPhpFastCacheGitHeadHash($cacheable = true)
108108
return $hash;
109109
}
110110

111-
if(function_exists('shell_exec')){
111+
if(\function_exists('shell_exec')){
112112
$stdout = shell_exec('git rev-parse --short HEAD');
113-
if(is_string($stdout)){
114-
$hash = trim($stdout);
113+
if(\is_string($stdout)){
114+
$hash = \trim($stdout);
115115
return "#{$hash}";
116116
}
117117
}
@@ -201,8 +201,8 @@ public static function getChangelog(): string
201201
public static function getPhpFastCacheChangelog(): string
202202
{
203203
$changelogFilename = __DIR__ . '/../../CHANGELOG.md';
204-
if(file_exists($changelogFilename)){
205-
$string = str_replace(["\r\n", "\r"], "\n", trim(file_get_contents($changelogFilename)));
204+
if(\file_exists($changelogFilename)){
205+
$string = \str_replace(["\r\n", "\r"], "\n", \trim(file_get_contents($changelogFilename)));
206206
if($string){
207207
return $string;
208208
}

src/phpFastCache/CacheManager.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,21 @@ public static function getInstance($driver = 'auto', array $config = [], $instan
203203
{
204204
static $badPracticeOmeter = [];
205205

206-
if ($instanceId !== null && !is_string($instanceId)) {
206+
if ($instanceId !== null && !\is_string($instanceId)) {
207207
throw new phpFastCacheInvalidArgumentException('The Instance ID must be a string');
208208
}
209209

210210
/**
211211
* @todo: Standardize a method for driver name
212212
*/
213213
$driver = self::standardizeDriverName($driver);
214-
$config = array_merge(self::$config, $config);
214+
$config = \array_merge(self::$config, $config);
215215
self::validateConfig($config);
216216
if (!$driver || $driver === 'Auto') {
217217
$driver = self::getAutoClass($config);
218218
}
219219

220-
$instance = $instanceId ?: crc32($driver . serialize($config));
220+
$instance = $instanceId ?: crc32($driver . \serialize($config));
221221

222222
if (!isset(self::$instances[ $instance ])) {
223223
$badPracticeOmeter[ $driver ] = 1;
@@ -277,7 +277,7 @@ public static function getInstance($driver = 'auto', array $config = [], $instan
277277
*/
278278
public static function getInstanceById($instanceId): ExtendedCacheItemPoolInterface
279279
{
280-
if ($instanceId !== null && !is_string($instanceId)) {
280+
if ($instanceId !== null && !\is_string($instanceId)) {
281281
throw new phpFastCacheInvalidArgumentException('The Instance ID must be a string');
282282
}
283283

@@ -347,7 +347,7 @@ public static function getAutoClass(array $config = [])
347347
*/
348348
public static function __callStatic($name, $arguments)
349349
{
350-
$options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []);
350+
$options = (\array_key_exists(0, $arguments) && \is_array($arguments) ? $arguments[ 0 ] : []);
351351

352352
return self::getInstance($name, $options);
353353
}
@@ -360,7 +360,7 @@ public static function clearInstances()
360360
self::$instances = [];
361361

362362
gc_collect_cycles();
363-
return !count(self::$instances);
363+
return !\count(self::$instances);
364364
}
365365

366366
/**
@@ -376,7 +376,7 @@ public static function getNamespacePath()
376376
*/
377377
public static function setNamespacePath($path)
378378
{
379-
self::$namespacePath = trim($path, "\\") . '\\';
379+
self::$namespacePath = \trim($path, "\\") . '\\';
380380
}
381381

382382
/**
@@ -386,9 +386,9 @@ public static function setNamespacePath($path)
386386
*/
387387
public static function setDefaultConfig($name, $value = null)
388388
{
389-
if (is_array($name)) {
390-
self::$config = array_merge(self::$config, $name);
391-
} else if (is_string($name)) {
389+
if (\is_array($name)) {
390+
self::$config = \array_merge(self::$config, $name);
391+
} else if (\is_string($name)) {
392392
self::$config[ $name ] = $value;
393393
} else {
394394
throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name');
@@ -450,7 +450,7 @@ public static function getStaticSystemDrivers()
450450
*/
451451
public static function getStaticAllDrivers()
452452
{
453-
return array_merge(self::getStaticSystemDrivers(), [
453+
return \array_merge(self::getStaticSystemDrivers(), [
454454
'Devtrue',
455455
'Devfalse',
456456
'Cookie',
@@ -464,10 +464,10 @@ public static function getStaticAllDrivers()
464464
*/
465465
public static function standardizeDriverName($driverName)
466466
{
467-
if (!is_string($driverName)) {
468-
throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName)));
467+
if (!\is_string($driverName)) {
468+
throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', \gettype($driverName)));
469469
}
470-
return ucfirst(strtolower(trim($driverName)));
470+
return \ucfirst(\strtolower(\trim($driverName)));
471471
}
472472

473473
/**
@@ -486,47 +486,47 @@ protected static function validateConfig(array $config)
486486
case 'ignoreSymfonyNotice':
487487
case 'htaccess':
488488
case 'compress_data':
489-
if (!is_bool($configValue)) {
489+
if (!\is_bool($configValue)) {
490490
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
491491
}
492492
break;
493493
case 'defaultTtl':
494-
if (!is_numeric($configValue)) {
494+
if (!\is_numeric($configValue)) {
495495
throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric");
496496
}
497497
break;
498498
case 'defaultKeyHashFunction':
499-
if (!is_string($configValue) && !function_exists($configValue)) {
499+
if (!\is_string($configValue) && !\function_exists($configValue)) {
500500
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string");
501501
}
502502
break;
503503
case 'securityKey':
504504
case 'path':
505-
if (!is_string($configValue) && (!is_bool($configValue) || $configValue)) {
505+
if (!\is_string($configValue) && (!\is_bool($configValue) || $configValue)) {
506506
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string or a false boolean");
507507
}
508508
break;
509509
case 'default_chmod':
510510
case 'limited_memory_each_object':
511-
if (!is_int($configValue)) {
511+
if (!\is_int($configValue)) {
512512
throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
513513
}
514514
break;
515515
case 'fallback':
516-
if (!is_bool($configValue) && !is_string($configValue)) {
516+
if (!\is_bool($configValue) && !\is_string($configValue)) {
517517
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean or string");
518518
}
519519
break;
520520
case 'cacheFileExtension':
521-
if (!is_string($configValue)) {
521+
if (!\is_string($configValue)) {
522522
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
523523
}
524-
if (strpos($configValue, '.') !== false) {
524+
if (\strpos($configValue, '.') !== false) {
525525
throw new phpFastCacheInvalidConfigurationException("{$configName} cannot contain a dot \".\"");
526526
}
527-
if (!in_array($configValue, self::$safeFileExtensions)) {
527+
if (!\in_array($configValue, self::$safeFileExtensions)) {
528528
throw new phpFastCacheInvalidConfigurationException(
529-
"{$configName} is not a safe extension, currently allowed extension: " . implode(', ', self::$safeFileExtensions)
529+
"{$configName} is not a safe extension, currently allowed extension: " . \implode(', ', self::$safeFileExtensions)
530530
);
531531
}
532532
break;

src/phpFastCache/Core/Item/ExtendedCacheItemInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public function getRemovedTags(): array;
190190
/**
191191
* Return the data as a well-formatted string.
192192
* Any scalar value will be casted to an array
193-
* @param int $option json_encode() options
194-
* @param int $depth json_encode() depth
193+
* @param int $option \json_encode() options
194+
* @param int $depth \json_encode() depth
195195
* @return string
196196
*/
197197
public function getDataAsJsonString($option = 0, $depth = 512): string;

src/phpFastCache/Core/Item/ItemBaseTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function isHit(): bool
132132
*/
133133
public function setHit($isHit): ExtendedCacheItemInterface
134134
{
135-
if (is_bool($isHit)) {
135+
if (\is_bool($isHit)) {
136136
$this->isHit = $isHit;
137137

138138
return $this;
@@ -157,7 +157,7 @@ public function expiresAt($expiration): ExtendedCacheItemInterface
157157
$this->eventManager->dispatch('CacheItemExpireAt', $this, $expiration);
158158
$this->expirationDate = $expiration;
159159
} else {
160-
throw new phpFastCacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . gettype($expiration));
160+
throw new phpFastCacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
161161
}
162162

163163
return $this;
@@ -170,7 +170,7 @@ public function expiresAt($expiration): ExtendedCacheItemInterface
170170
*/
171171
public function expiresAfter($time)
172172
{
173-
if (is_numeric($time)) {
173+
if (\is_numeric($time)) {
174174
if ($time <= 0) {
175175
/**
176176
* 5 years, however memcached or memory cached will gone when u restart it

0 commit comments

Comments
 (0)