Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa0dfe0

Browse files
committed
Apply doctrine/cs v4
1 parent e1f38aa commit fa0dfe0

54 files changed

Lines changed: 444 additions & 423 deletions

Some content is hidden

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

.scrutinizer.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@ build:
33
php:
44
version: 7.1.0
55

6-
before_commands:
7-
- "composer install --no-dev --prefer-source"
6+
tests:
7+
override:
8+
- php-scrutinizer-run
9+
- phpcs-run
10+
11+
dependencies:
12+
override:
13+
- composer install --no-interaction --prefer-dist
814

915
tools:
1016
external_code_coverage:
1117
timeout: 1800
1218
php_code_coverage:
1319
enabled: true
14-
php_code_sniffer:
15-
enabled: true
16-
config:
17-
standard: PSR2
18-
filter:
19-
paths: ["lib/*", "tests/*"]
2020
php_cpd:
2121
enabled: true
2222
excluded_dirs: ["vendor"]
23-
php_cs_fixer:
24-
enabled: true
25-
config:
26-
level: all
27-
filter:
28-
paths: ["lib/*", "tests/*"]
2923
php_loc:
3024
enabled: true
3125
excluded_dirs: ["vendor"]

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"mongodb/mongodb": "^1.1",
2121
"phpunit/phpunit": "^7.0",
2222
"predis/predis": "~1.0",
23-
"squizlabs/php_codesniffer": "^3.0",
24-
"doctrine/coding-standard": "^1.0"
23+
"doctrine/coding-standard": "^4.0"
2524
},
2625
"suggest": {
2726
"alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver"

lib/Doctrine/Common/Cache/ApcCache.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace Doctrine\Common\Cache;
44

5+
use const PHP_VERSION_ID;
6+
use function apc_cache_info;
7+
use function apc_clear_cache;
8+
use function apc_delete;
9+
use function apc_exists;
10+
use function apc_fetch;
11+
use function apc_sma_info;
12+
use function apc_store;
13+
514
/**
615
* APC cache provider.
716
*
817
* @link www.doctrine-project.org
918
* @deprecated since version 1.6, use ApcuCache instead
10-
* @since 2.0
11-
* @author Benjamin Eberlei <[email protected]>
12-
* @author Guilherme Blanco <[email protected]>
13-
* @author Jonathan Wage <[email protected]>
14-
* @author Roman Borschel <[email protected]>
15-
* @author David Abdemoulaie <[email protected]>
1619
*/
1720
class ApcCache extends CacheProvider
1821
{
@@ -85,9 +88,9 @@ protected function doGetStats()
8588

8689
// @TODO - Temporary fix @see https://github.com/krakjoe/apcu/pull/42
8790
if (PHP_VERSION_ID >= 50500) {
88-
$info['num_hits'] = isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'];
89-
$info['num_misses'] = isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'];
90-
$info['start_time'] = isset($info['start_time']) ? $info['start_time'] : $info['stime'];
91+
$info['num_hits'] = $info['num_hits'] ?? $info['nhits'];
92+
$info['num_misses'] = $info['num_misses'] ?? $info['nmisses'];
93+
$info['start_time'] = $info['start_time'] ?? $info['stime'];
9194
}
9295

9396
return [

lib/Doctrine/Common/Cache/ApcuCache.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
namespace Doctrine\Common\Cache;
44

5+
use function apcu_cache_info;
6+
use function apcu_clear_cache;
7+
use function apcu_delete;
8+
use function apcu_exists;
9+
use function apcu_fetch;
10+
use function apcu_sma_info;
11+
use function apcu_store;
12+
use function count;
13+
514
/**
615
* APCu cache provider.
716
*
817
* @link www.doctrine-project.org
9-
* @since 1.6
10-
* @author Kévin Dunglas <[email protected]>
1118
*/
1219
class ApcuCache extends CacheProvider
1320
{
@@ -51,7 +58,7 @@ protected function doDeleteMultiple(array $keys)
5158
{
5259
$result = apcu_delete($keys);
5360

54-
return false !== $result && count($result) !== count($keys);
61+
return $result !== false && count($result) !== count($keys);
5562
}
5663

5764
/**

lib/Doctrine/Common/Cache/ArrayCache.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,25 @@
22

33
namespace Doctrine\Common\Cache;
44

5+
use function time;
6+
57
/**
68
* Array cache driver.
79
*
810
* @link www.doctrine-project.org
9-
* @since 2.0
10-
* @author Benjamin Eberlei <[email protected]>
11-
* @author Guilherme Blanco <[email protected]>
12-
* @author Jonathan Wage <[email protected]>
13-
* @author Roman Borschel <[email protected]>
14-
* @author David Abdemoulaie <[email protected]>
1511
*/
1612
class ArrayCache extends CacheProvider
1713
{
18-
/**
19-
* @var array[] $data each element being a tuple of [$data, $expiration], where the expiration is int|bool
20-
*/
14+
/** @var array[] $data each element being a tuple of [$data, $expiration], where the expiration is int|bool */
2115
private $data = [];
2216

23-
/**
24-
* @var int
25-
*/
17+
/** @var int */
2618
private $hitsCount = 0;
2719

28-
/**
29-
* @var int
30-
*/
20+
/** @var int */
3121
private $missesCount = 0;
3222

33-
/**
34-
* @var int
35-
*/
23+
/** @var int */
3624
private $upTime;
3725

3826
/**
@@ -48,7 +36,7 @@ public function __construct()
4836
*/
4937
protected function doFetch($id)
5038
{
51-
if ( ! $this->doContains($id)) {
39+
if (! $this->doContains($id)) {
5240
$this->missesCount += 1;
5341

5442
return false;
@@ -64,7 +52,7 @@ protected function doFetch($id)
6452
*/
6553
protected function doContains($id)
6654
{
67-
if ( ! isset($this->data[$id])) {
55+
if (! isset($this->data[$id])) {
6856
return false;
6957
}
7058

lib/Doctrine/Common/Cache/Cache.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,20 @@
66
* Interface for cache drivers.
77
*
88
* @link www.doctrine-project.org
9-
* @since 2.0
10-
* @author Benjamin Eberlei <[email protected]>
11-
* @author Guilherme Blanco <[email protected]>
12-
* @author Jonathan Wage <[email protected]>
13-
* @author Roman Borschel <[email protected]>
14-
* @author Fabio B. Silva <[email protected]>
15-
* @author Kévin Dunglas <[email protected]>
169
*/
1710
interface Cache
1811
{
19-
const STATS_HITS = 'hits';
20-
const STATS_MISSES = 'misses';
21-
const STATS_UPTIME = 'uptime';
22-
const STATS_MEMORY_USAGE = 'memory_usage';
23-
const STATS_MEMORY_AVAILABLE = 'memory_available';
12+
public const STATS_HITS = 'hits';
13+
public const STATS_MISSES = 'misses';
14+
public const STATS_UPTIME = 'uptime';
15+
public const STATS_MEMORY_USAGE = 'memory_usage';
16+
public const STATS_MEMORY_AVAILABLE = 'memory_available';
2417
/**
2518
* Only for backward compatibility (may be removed in next major release)
2619
*
2720
* @deprecated
2821
*/
29-
const STATS_MEMORY_AVAILIABLE = 'memory_available';
22+
public const STATS_MEMORY_AVAILIABLE = 'memory_available';
3023

3124
/**
3225
* Fetches an entry from the cache.
@@ -91,8 +84,6 @@ public function delete($id);
9184
* - <b>memory_available</b>
9285
* Memory allowed to use for storage.
9386
*
94-
* @since 2.2
95-
*
9687
* @return array|null An associative array with server's statistics if available, NULL otherwise.
9788
*/
9889
public function getStats();

lib/Doctrine/Common/Cache/CacheProvider.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
namespace Doctrine\Common\Cache;
44

5+
use function array_combine;
6+
use function array_key_exists;
7+
use function array_map;
8+
use function sprintf;
9+
510
/**
611
* Base class for cache provider implementations.
712
*
8-
* @since 2.2
9-
* @author Benjamin Eberlei <[email protected]>
10-
* @author Guilherme Blanco <[email protected]>
11-
* @author Jonathan Wage <[email protected]>
12-
* @author Roman Borschel <[email protected]>
13-
* @author Fabio B. Silva <[email protected]>
14-
* @author Benoit Burnichon <[email protected]>
1513
*/
1614
abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, MultiOperationCache
1715
{
18-
const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
16+
public const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
1917

2018
/**
2119
* The namespace to prefix all cache ids with.
@@ -27,7 +25,7 @@ abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, M
2725
/**
2826
* The namespace version.
2927
*
30-
* @var integer|null
28+
* @var int|null
3129
*/
3230
private $namespaceVersion;
3331

@@ -79,9 +77,11 @@ public function fetchMultiple(array $keys)
7977
// no internal array function supports this sort of mapping: needs to be iterative
8078
// this filters and combines keys in one pass
8179
foreach ($namespacedKeys as $requestedKey => $namespacedKey) {
82-
if (isset($items[$namespacedKey]) || array_key_exists($namespacedKey, $items)) {
83-
$foundItems[$requestedKey] = $items[$namespacedKey];
80+
if (! isset($items[$namespacedKey]) && ! array_key_exists($namespacedKey, $items)) {
81+
continue;
8482
}
83+
84+
$foundItems[$requestedKey] = $items[$namespacedKey];
8585
}
8686

8787
return $foundItems;
@@ -121,7 +121,7 @@ public function save($id, $data, $lifeTime = 0)
121121
*/
122122
public function deleteMultiple(array $keys)
123123
{
124-
return $this->doDeleteMultiple(array_map(array($this, 'getNamespacedId'), $keys));
124+
return $this->doDeleteMultiple(array_map([$this, 'getNamespacedId'], $keys));
125125
}
126126

127127
/**
@@ -181,8 +181,6 @@ private function getNamespacedId(string $id) : string
181181

182182
/**
183183
* Returns the namespace cache key.
184-
*
185-
* @return string
186184
*/
187185
private function getNamespaceCacheKey() : string
188186
{
@@ -191,12 +189,10 @@ private function getNamespaceCacheKey() : string
191189

192190
/**
193191
* Returns the namespace version.
194-
*
195-
* @return integer
196192
*/
197193
private function getNamespaceVersion() : int
198194
{
199-
if (null !== $this->namespaceVersion) {
195+
if ($this->namespaceVersion !== null) {
200196
return $this->namespaceVersion;
201197
}
202198

@@ -217,9 +213,12 @@ protected function doFetchMultiple(array $keys)
217213
$returnValues = [];
218214

219215
foreach ($keys as $key) {
220-
if (false !== ($item = $this->doFetch($key)) || $this->doContains($key)) {
221-
$returnValues[$key] = $item;
216+
$item = $this->doFetch($key);
217+
if ($item === false && ! $this->doContains($key)) {
218+
continue;
222219
}
220+
221+
$returnValues[$key] = $item;
223222
}
224223

225224
return $returnValues;
@@ -246,9 +245,9 @@ abstract protected function doContains($id);
246245
/**
247246
* Default implementation of doSaveMultiple. Each driver that supports multi-put should override it.
248247
*
249-
* @param array $keysAndValues Array of keys and values to save in cache
250-
* @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
251-
* cache entries (0 => infinite lifeTime).
248+
* @param array $keysAndValues Array of keys and values to save in cache
249+
* @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
250+
* cache entries (0 => infinite lifeTime).
252251
*
253252
* @return bool TRUE if the operation was successful, FALSE if it wasn't.
254253
*/
@@ -257,9 +256,11 @@ protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
257256
$success = true;
258257

259258
foreach ($keysAndValues as $key => $value) {
260-
if ( ! $this->doSave($key, $value, $lifetime)) {
261-
$success = false;
259+
if ($this->doSave($key, $value, $lifetime)) {
260+
continue;
262261
}
262+
263+
$success = false;
263264
}
264265

265266
return $success;
@@ -289,9 +290,11 @@ protected function doDeleteMultiple(array $keys)
289290
$success = true;
290291

291292
foreach ($keys as $key) {
292-
if ( ! $this->doDelete($key)) {
293-
$success = false;
293+
if ($this->doDelete($key)) {
294+
continue;
294295
}
296+
297+
$success = false;
295298
}
296299

297300
return $success;
@@ -316,8 +319,6 @@ abstract protected function doFlush();
316319
/**
317320
* Retrieves cached information from the data store.
318321
*
319-
* @since 2.2
320-
*
321322
* @return array|null An associative array with server's statistics if available, NULL otherwise.
322323
*/
323324
abstract protected function doGetStats();

lib/Doctrine/Common/Cache/ChainCache.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
namespace Doctrine\Common\Cache;
44

5+
use function array_values;
6+
use function count;
7+
use function iterator_to_array;
8+
59
/**
610
* Cache provider that allows to easily chain multiple cache providers
7-
*
8-
* @author Michaël Gallego <[email protected]>
911
*/
1012
class ChainCache extends CacheProvider
1113
{
12-
/**
13-
* @var CacheProvider[]
14-
*/
14+
/** @var CacheProvider[] */
1515
private $cacheProviders = [];
1616

1717
/**
18-
* Constructor
19-
*
2018
* @param CacheProvider[] $cacheProviders
2119
*/
2220
public function __construct($cacheProviders = [])

0 commit comments

Comments
 (0)