Skip to content

Commit 67960f2

Browse files
authored
Merge pull request #482 from Geolim4/final
Multiple Scrutinizer's feedback fixes
2 parents a5648ee + 29e45ed commit 67960f2

Some content is hidden

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

67 files changed

+357
-335
lines changed

.scrutinizer.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
before_commands:
22
- "composer install --no-dev --prefer-source"
3-
3+
- "composer require predis/predis \"~1.1.0\""
4+
- "composer require mongodb/mongodb \"^1.1\""
5+
- "composer require phpfastcache/phpssdb ~1.0.0\""
6+
- "composer require phpfastcache/couchdb \"~1.0.0\""
47
filter:
58
excluded_paths: ["bin/*", "docs/*", "examples/*", "var/*", "vendor/*", "tests/*"]
69
checks:
@@ -22,4 +25,11 @@ tools:
2225
php_mess_detector:
2326
enabled: true
2427
filter:
25-
paths: ["src/*"]
28+
paths: ["src/*"]
29+
build:
30+
environment:
31+
php:
32+
version: 5.6
33+
dependencies:
34+
before:
35+
- pecl install cassandra

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ php:
3232
# - 5.5
3333
- 5.6
3434
- 7.0
35+
- 7.1
3536
- nightly
3637
- hhvm
3738

src/autoload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
if (is_readable($path)) {
3333
require_once $path;
34-
}else{
34+
} else {
3535
trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
3636
}
3737
return;
@@ -40,7 +40,7 @@
4040

4141
if (is_readable($path)) {
4242
require_once $path;
43-
}else{
43+
} else {
4444
trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR);
4545
}
4646
return;
@@ -55,6 +55,6 @@
5555
});
5656

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

src/phpFastCache/Api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author Georges.L (Geolim4) <[email protected]>
1212
*
1313
*/
14+
1415
namespace phpFastCache;
1516

1617
/**

src/phpFastCache/CacheManager.php

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author Georges.L (Geolim4) <[email protected]>
1212
*
1313
*/
14+
1415
namespace phpFastCache;
1516

1617
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
@@ -58,7 +59,7 @@ class CacheManager
5859
public static $WriteHits = 0;
5960

6061
/**
61-
* @var ExtendedCacheItemPoolInterface[]
62+
* @var array
6263
*/
6364
protected static $config = [
6465
/**
@@ -168,7 +169,10 @@ class CacheManager
168169
* @var array
169170
*/
170171
protected static $safeFileExtensions = [
171-
'txt', 'cache', 'db', 'pfc'
172+
'txt',
173+
'cache',
174+
'db',
175+
'pfc',
172176
];
173177

174178
/**
@@ -204,39 +208,41 @@ public static function getInstance($driver = 'auto', array $config = [])
204208

205209
$instance = crc32($driver . serialize($config));
206210
if (!isset(self::$instances[ $instance ])) {
207-
$badPracticeOmeter[$driver] = 1;
208-
if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){
209-
trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE);
211+
$badPracticeOmeter[ $driver ] = 1;
212+
if (!$config[ 'ignoreSymfonyNotice' ] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) {
213+
trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle',
214+
E_USER_NOTICE);
210215
}
211216
$class = self::getNamespacePath() . $driver . '\Driver';
212-
try{
217+
try {
213218
self::$instances[ $instance ] = new $class($config);
214219
self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
215-
}catch(phpFastCacheDriverCheckException $e){
216-
if($config['fallback']){
217-
try{
218-
$fallback = self::standardizeDriverName($config['fallback']);
219-
if($fallback !== $driver){
220+
} catch (phpFastCacheDriverCheckException $e) {
221+
if ($config[ 'fallback' ]) {
222+
try {
223+
$fallback = self::standardizeDriverName($config[ 'fallback' ]);
224+
if ($fallback !== $driver) {
220225
$class = self::getNamespacePath() . $fallback . '\Driver';
221226
self::$instances[ $instance ] = new $class($config);
222227
self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
223-
trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
224-
}else{
228+
trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver,
229+
$fallback), E_USER_WARNING);
230+
} else {
225231
throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e);
226232
}
227-
}catch (phpFastCacheInvalidArgumentException $e){
233+
} catch (phpFastCacheInvalidArgumentException $e) {
228234
throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
229235
}
230-
}else{
236+
} else {
231237
throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
232238
}
233239
}
234-
} else if($badPracticeOmeter[$driver] >= 5){
240+
} else if ($badPracticeOmeter[ $driver ] >= 5) {
235241
trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
236242
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
237243
}
238244

239-
$badPracticeOmeter[$driver]++;
245+
$badPracticeOmeter[ $driver ]++;
240246

241247
return self::$instances[ $instance ];
242248
}
@@ -340,9 +346,9 @@ public static function setDefaultConfig($name, $value = null)
340346
{
341347
if (is_array($name)) {
342348
self::$config = array_merge(self::$config, $name);
343-
} else if (is_string($name)){
349+
} else if (is_string($name)) {
344350
self::$config[ $name ] = $value;
345-
}else{
351+
} else {
346352
throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name');
347353
}
348354
}
@@ -413,7 +419,7 @@ public static function getStaticAllDrivers()
413419
*/
414420
public static function standardizeDriverName($driverName)
415421
{
416-
if(!is_string($driverName)){
422+
if (!is_string($driverName)) {
417423
throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName)));
418424
}
419425
return ucfirst(strtolower(trim($driverName)));
@@ -428,81 +434,80 @@ public static function standardizeDriverName($driverName)
428434
protected static function validateConfig(array $config)
429435
{
430436
foreach ($config as $configName => $configValue) {
431-
switch($configName)
432-
{
437+
switch ($configName) {
433438
case 'itemDetailedDate':
434-
if(!is_bool($configValue)){
439+
if (!is_bool($configValue)) {
435440
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
436441
}
437442
break;
438443
case 'autoTmpFallback':
439-
if(!is_bool($configValue)){
444+
if (!is_bool($configValue)) {
440445
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
441446
}
442447
break;
443448
case 'secureFileManipulation':
444-
if(!is_bool($configValue)){
449+
if (!is_bool($configValue)) {
445450
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
446451
}
447452
break;
448453
case 'ignoreSymfonyNotice':
449-
if(!is_bool($configValue)){
454+
if (!is_bool($configValue)) {
450455
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
451456
}
452457
break;
453458
case 'defaultTtl':
454-
if(!is_numeric($configValue)){
459+
if (!is_numeric($configValue)) {
455460
throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric");
456461
}
457462
break;
458463
case 'defaultKeyHashFunction':
459-
if(!is_string($configValue) && !function_exists($configValue)){
464+
if (!is_string($configValue) && !function_exists($configValue)) {
460465
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string");
461466
}
462467
break;
463468
case 'securityKey':
464-
if(!is_string($configValue)){
469+
if (!is_string($configValue)) {
465470
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
466471
}
467472
break;
468473
case 'htaccess':
469-
if(!is_bool($configValue)){
474+
if (!is_bool($configValue)) {
470475
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
471476
}
472477
break;
473478
case 'default_chmod':
474-
if(!is_int($configValue)){
479+
if (!is_int($configValue)) {
475480
throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
476481
}
477482
break;
478483
case 'path':
479-
if(!is_string($configValue)){
484+
if (!is_string($configValue)) {
480485
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
481486
}
482487
break;
483488
case 'fallback':
484-
if(!is_bool($configValue) && !is_string($configValue)){
489+
if (!is_bool($configValue) && !is_string($configValue)) {
485490
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean or string");
486491
}
487492
break;
488493
case 'limited_memory_each_object':
489-
if(!is_int($configValue)){
494+
if (!is_int($configValue)) {
490495
throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
491496
}
492497
break;
493498
case 'compress_data':
494-
if(!is_bool($configValue)){
499+
if (!is_bool($configValue)) {
495500
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
496501
}
497502
break;
498503
case 'cacheFileExtension':
499-
if(!is_string($configValue)){
504+
if (!is_string($configValue)) {
500505
throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
501506
}
502-
if(strpos($configValue, '.') !== false){
507+
if (strpos($configValue, '.') !== false) {
503508
throw new phpFastCacheInvalidConfigurationException("{$configName} cannot contain a dot \".\"");
504509
}
505-
if(!in_array($configValue, self::$safeFileExtensions)){
510+
if (!in_array($configValue, self::$safeFileExtensions)) {
506511
throw new phpFastCacheInvalidConfigurationException(
507512
"{$configName} is not a safe extension, currently allowed extension: " . implode(', ', self::$safeFileExtensions)
508513
);

src/phpFastCache/Core/Item/ExtendedCacheItemInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
namespace phpFastCache\Core\Item;
1616

17+
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
1718
use phpFastCache\EventManager;
1819
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
19-
use Psr\Cache\CacheItemInterface;
20-
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
2120
use phpFastCache\Exceptions\phpFastCacheLogicException;
21+
use Psr\Cache\CacheItemInterface;
2222

2323
/**
2424
* Interface ExtendedCacheItemInterface
@@ -64,7 +64,7 @@ public function setExpirationDate(\DateTimeInterface $expiration);
6464
* @throws phpFastCacheLogicException
6565
*/
6666
public function getCreationDate();
67-
67+
6868
/**
6969
* @return \DateTimeInterface
7070
* @throws phpFastCacheLogicException

src/phpFastCache/Core/Item/ItemBaseTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author Georges.L (Geolim4) <[email protected]>
1212
*
1313
*/
14+
1415
namespace phpFastCache\Core\Item;
1516

1617
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;

0 commit comments

Comments
 (0)