Skip to content

Commit a3bb3c8

Browse files
committed
Enforced more argument type hint & absolute core php function namespaces
1 parent c1752b8 commit a3bb3c8

File tree

15 files changed

+51
-57
lines changed

15 files changed

+51
-57
lines changed

lib/Phpfastcache/Autoload/Autoload.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ class Autoload{}
3232
* then we return here.
3333
*/
3434
return;
35-
} else if (\strpos($entity, 'Psr\Cache') === 0) {
36-
$path = PFC_BIN_DIR . 'dependencies/Psr/Cache/src/' . \substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
35+
}
36+
37+
if (\strpos($entity, 'Psr\Cache') === 0) {
38+
$path = PFC_BIN_DIR . 'dependencies/Psr/Cache/src/' . \substr(\strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
3739

3840
if (\is_readable($path)) {
3941
require_once $path;
4042
} else {
41-
trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
43+
\trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
4244
}
4345
return;
44-
} else if (\strpos($entity, 'Psr\SimpleCache') === 0) {
45-
$path = PFC_BIN_DIR . 'dependencies/Psr/SimpleCache/src/' . \substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
46+
}
47+
48+
if (\strpos($entity, 'Psr\SimpleCache') === 0) {
49+
$path = PFC_BIN_DIR . 'dependencies/Psr/SimpleCache/src/' . \substr(\strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
4650

4751
if (\is_readable($path)) {
4852
require_once $path;
4953
} else {
50-
trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR);
54+
\trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR);
5155
}
5256
return;
5357
}
@@ -60,7 +64,7 @@ class Autoload{}
6064
}
6165
});
6266

63-
if ((!\defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && \class_exists('Composer\Autoload\ClassLoader')) {
64-
trigger_error('Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
67+
if ((!\defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && \class_exists(\Composer\Autoload\ClassLoader::class)) {
68+
\trigger_error('Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
6569
E_USER_WARNING);
6670
}

lib/Phpfastcache/CacheManager.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ class CacheManager
110110
* @throws PhpfastcacheInvalidArgumentException
111111
* @throws PhpfastcacheDriverException
112112
*/
113-
public static function getInstance(string $driver = 'auto', $config = null, string $instanceId = null): ExtendedCacheItemPoolInterface
113+
public static function getInstance(string $driver = self::AUTOMATIC_DRIVER_CLASS, $config = null, string $instanceId = null): ExtendedCacheItemPoolInterface
114114
{
115115
if (\is_array($config)) {
116116
$config = new ConfigurationOption($config);
117-
trigger_error(
117+
\trigger_error(
118118
'The CacheManager will drops the support of primitive configuration arrays, use a "\Phpfastcache\Config\ConfigurationOption" object instead',
119119
E_USER_DEPRECATED
120120
);
@@ -156,7 +156,7 @@ public static function getInstance(string $driver = 'auto', $config = null, stri
156156
try {
157157
$fallback = $config->getFallback();
158158
$config->setFallback('');
159-
trigger_error(\sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
159+
\trigger_error(\sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
160160
return self::getInstance($fallback, $config->getFallbackConfig());
161161
} catch (PhpfastcacheInvalidArgumentException $e) {
162162
throw new PhpfastcacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
@@ -166,7 +166,7 @@ public static function getInstance(string $driver = 'auto', $config = null, stri
166166
}
167167
}
168168
} else if (self::$badPracticeOmeter[ $driver ] >= 2) {
169-
trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
169+
\trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
170170
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
171171
}
172172

@@ -295,7 +295,7 @@ public static function getNamespacePath(): string
295295
*/
296296
public static function getDefaultNamespacePath(): string
297297
{
298-
return __NAMESPACE__ . '\Drivers\\';
298+
return self::CORE_DRIVER_NAMESPACE;
299299
}
300300

301301
/**
@@ -304,7 +304,7 @@ public static function getDefaultNamespacePath(): string
304304
*/
305305
public static function setNamespacePath($path)
306306
{
307-
trigger_error('This method has been deprecated as of V7, please use cache manager "override" or "custom driver" features instead', E_USER_DEPRECATED);
307+
\trigger_error('This method has been deprecated as of V7, please use cache manager "override" or "custom driver" features instead', E_USER_DEPRECATED);
308308
self::$namespacePath = \trim($path, "\\") . '\\';
309309
}
310310

@@ -330,7 +330,7 @@ public static function getDefaultConfig(): ConfigurationOption
330330
*/
331331
public static function getStaticSystemDrivers(): array
332332
{
333-
trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', __METHOD__), E_USER_DEPRECATED);
333+
\trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', __METHOD__), E_USER_DEPRECATED);
334334
return [
335335
'Apc',
336336
'Apcu',
@@ -362,7 +362,7 @@ public static function getStaticSystemDrivers(): array
362362
*/
363363
public static function getStaticAllDrivers(): array
364364
{
365-
trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', __METHOD__), E_USER_DEPRECATED);
365+
\trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', __METHOD__), E_USER_DEPRECATED);
366366
return \array_merge(self::getStaticSystemDrivers(), [
367367
'Devtrue',
368368
'Devfalse',

lib/Phpfastcache/Config/ConfigurationOption.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function __construct(...$args)
151151
*/
152152
public function getOption(string $optionName)
153153
{
154-
trigger_error(sprintf('Method "%s" is deprecated, use "getOptionName()" instead', __METHOD__), E_USER_DEPRECATED);
154+
\trigger_error(sprintf('Method "%s" is deprecated, use "getOptionName()" instead', __METHOD__), E_USER_DEPRECATED);
155155
return $this->$optionName ?? null;
156156
}
157157

@@ -217,7 +217,7 @@ public function isIgnoreSymfonyNotice(): bool
217217
public function setIgnoreSymfonyNotice(bool $ignoreSymfonyNotice): self
218218
{
219219
if($ignoreSymfonyNotice){
220-
trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', E_USER_DEPRECATED);
220+
\trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', E_USER_DEPRECATED);
221221
}
222222
$this->ignoreSymfonyNotice = $ignoreSymfonyNotice;
223223
return $this;

lib/Phpfastcache/Core/Item/ItemBaseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function expiresAfter($time)
197197

198198
$this->expirationDate = (new \DateTime())->add($time);
199199
} else {
200-
throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', gettype($time)));
200+
throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time)));
201201
}
202202

203203
return $this;

lib/Phpfastcache/Core/Item/ItemExtendedTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public function getTagsAsString($separator = ', '): string
379379
*/
380380
public function removeTag($tagName): ExtendedCacheItemInterface
381381
{
382-
if (($key = array_search($tagName, $this->tags)) !== false) {
382+
if (($key = \array_search($tagName, $this->tags)) !== false) {
383383
unset($this->tags[ $key ]);
384384
$this->removedTags[] = $tagName;
385385
}
@@ -461,6 +461,6 @@ final public function __debugInfo()
461461
$info = \get_object_vars($this);
462462
$info[ 'driver' ] = 'object(' . \get_class($info[ 'driver' ]) . ')';
463463

464-
return (array)$info;
464+
return $info;
465465
}
466466
}

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function getItem($key)
172172
$item->setHit(true);
173173
}
174174
} else {
175-
$item->expiresAfter(abs((int)$this->getConfig()[ 'defaultTtl' ]));
175+
$item->expiresAfter(\abs((int)$this->getConfig()[ 'defaultTtl' ]));
176176
}
177177
}
178178
}

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace Phpfastcache\Core\Pool;
1717

18+
use Phpfastcache\CacheManager;
1819
use Phpfastcache\Config\ConfigurationOption;
1920
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2021
use Phpfastcache\Exceptions\{
@@ -99,7 +100,7 @@ public function getConfig(): ConfigurationOption
99100
*/
100101
public function getConfigOption($optionName)
101102
{
102-
trigger_error(sprintf('Method "%s" is deprecated, use "getConfig()->getOptionName()" instead', __METHOD__), E_USER_DEPRECATED);
103+
\trigger_error(sprintf('Method "%s" is deprecated, use "getConfig()->getOptionName()" instead', __METHOD__), E_USER_DEPRECATED);
103104
return $this->getConfig()->getOption($optionName);
104105
}
105106

@@ -145,17 +146,6 @@ protected function isPHPModule(): bool
145146
return (PHP_SAPI === 'apache2handler' || \strpos(PHP_SAPI, 'handler') !== false);
146147
}
147148

148-
149-
/**
150-
* @param $class
151-
* @return bool
152-
*/
153-
protected function driverExists($class): bool
154-
{
155-
return \class_exists("\\phpFastCache\\Drivers\\{$class}");
156-
}
157-
158-
159149
/**
160150
* @param \Phpfastcache\Core\Item\ExtendedCacheItemInterface $item
161151
* @return array
@@ -284,7 +274,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
284274
* that has slow performances
285275
*/
286276

287-
$tagsItem->set(array_merge((array)$data, [$item->getKey() => $expTimestamp]));
277+
$tagsItem->set(\array_merge((array)$data, [$item->getKey() => $expTimestamp]));
288278

289279
/**
290280
* Set the expiration date
@@ -388,7 +378,7 @@ public static function getValidOptions(): array
388378
*/
389379
public static function getConfigClass(): string
390380
{
391-
$localConfigClass = substr(static::class, 0, strrpos(static::class, '\\')) . '\Config';
381+
$localConfigClass = \substr(static::class, 0, \strrpos(static::class, '\\')) . '\Config';
392382
if(\class_exists($localConfigClass) && is_a($localConfigClass, ConfigurationOption::class, true)){
393383
return $localConfigClass;
394384
}

lib/Phpfastcache/Drivers/Mongodb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function driverCheck(): bool
6161
$mongoExtensionExists = class_exists(\MongoDB\Driver\Manager::class);
6262

6363
if (!$mongoExtensionExists && class_exists(\MongoClient::class)) {
64-
trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library.
64+
\trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library.
6565
For MongoDb with Mongo PECL support use Mongo Driver.', E_USER_ERROR);
6666
}
6767

lib/Phpfastcache/Drivers/Predis/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Driver implements ExtendedCacheItemPoolInterface
4343
public function driverCheck(): bool
4444
{
4545
if (extension_loaded('Redis')) {
46-
trigger_error('The native Redis extension is installed, you should use Redis instead of Predis to increase performances', E_USER_NOTICE);
46+
\trigger_error('The native Redis extension is installed, you should use Redis instead of Predis to increase performances', E_USER_NOTICE);
4747
}
4848

4949
return \class_exists('Predis\Client');

lib/Phpfastcache/Entities/ItemBatch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class ItemBatch
3535

3636
/**
3737
* ItemBatch constructor.
38-
* @param $itemKey
38+
* @param string $itemKey
3939
* @param \DateTimeInterface $itemDate
4040
* @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentTypeException
4141
*/
42-
public function __construct($itemKey, \DateTimeInterface $itemDate)
42+
public function __construct(string $itemKey, \DateTimeInterface $itemDate)
4343
{
4444
if (\is_string($itemKey)) {
4545
$this->itemKey = $itemKey;

0 commit comments

Comments
 (0)