Skip to content

Commit da97c83

Browse files
committed
style: enforce symfony 2025 rules
1 parent 9d450ee commit da97c83

44 files changed

Lines changed: 264 additions & 189 deletions

Some content is hidden

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

‎.php-cs-fixer.dist.php‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,38 @@
22

33
declare(strict_types=1);
44

5+
$header = <<<'HEADER'
6+
This file is part of php-cache organization.
7+
8+
(c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
9+
10+
This source file is subject to the MIT license that is bundled
11+
with this source code in the file LICENSE.
12+
HEADER;
13+
514
$finder = PhpCsFixer\Finder::create()
615
->in(__DIR__)
7-
->exclude('vendor');
16+
->exclude([
17+
'Resources',
18+
'vendor',
19+
]);
820

921
return (new PhpCsFixer\Config())
1022
->setRules([
1123
'@Symfony' => true,
24+
'@Symfony:risky' => true,
25+
'declare_strict_types' => false,
26+
'header_comment' => ['header' => $header],
27+
'modern_serialization_methods' => false,
28+
'no_php4_constructor' => false,
29+
'no_trailing_whitespace_in_string' => true,
30+
'php_unit_construct' => false,
31+
'php_unit_mock_short_will_return' => false,
32+
'php_unit_set_up_tear_down_visibility' => false,
33+
'php_unit_test_annotation' => false,
1234
'protected_to_private' => false,
35+
'static_lambda' => false,
1336
'void_return' => false,
1437
])
38+
->setRiskyAllowed(true)
1539
->setFinder($finder);

‎script/check-coverage.php‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* This file is part of php-cache organization.
7+
*
8+
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
12+
*/
13+
514
$arguments = $_SERVER['argv'] ?? null;
615
if (!is_array($arguments) || 3 !== count($arguments) || !is_string($arguments[1]) || !is_string($arguments[2])) {
7-
fwrite(STDERR, "Usage: check-coverage.php <clover.xml> <minimum-percent>\n");
16+
fwrite(\STDERR, "Usage: check-coverage.php <clover.xml> <minimum-percent>\n");
817

918
exit(2);
1019
}
1120

1221
$coverage = simplexml_load_file($arguments[1]);
1322
if (false === $coverage || !isset($coverage->project->metrics)) {
14-
fwrite(STDERR, sprintf("Could not read Clover metrics from %s.\n", $arguments[1]));
23+
fwrite(\STDERR, sprintf("Could not read Clover metrics from %s.\n", $arguments[1]));
1524

1625
exit(2);
1726
}
@@ -21,7 +30,7 @@
2130
$coveredStatements = (int) $metrics['coveredstatements'];
2231
$minimum = (float) $arguments[2];
2332
if (0 === $statements) {
24-
fwrite(STDERR, "The coverage report does not contain executable statements.\n");
33+
fwrite(\STDERR, "The coverage report does not contain executable statements.\n");
2534

2635
exit(2);
2736
}
@@ -31,7 +40,7 @@
3140
printf("Line coverage: %.2f%% (%d/%d)\n", $percentage, $coveredStatements, $statements);
3241

3342
if ($percentage < $minimum) {
34-
fwrite(STDERR, sprintf("Coverage must be at least %.2f%%.\n", $minimum));
43+
fwrite(\STDERR, sprintf("Coverage must be at least %.2f%%.\n", $minimum));
3544

3645
exit(1);
3746
}

‎src/Adapter/Apcu/ApcuCachePool.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ protected function fetchObjectFromCache(string $key): array
3737

3838
$success = false;
3939
$record = apcu_fetch($key, $success);
40-
if (!$success || !is_array($record) || !array_is_list($record) || 3 !== count($record)) {
40+
if (!$success || !\is_array($record) || !array_is_list($record) || 3 !== \count($record)) {
4141
return [false, null, [], null];
4242
}
4343

4444
$tags = $record[1];
45-
if (!is_array($tags)) {
45+
if (!\is_array($tags)) {
4646
return [false, null, [], null];
4747
}
4848

4949
$decodedTags = [];
5050
foreach ($tags as $tag) {
51-
if (!is_string($tag)) {
51+
if (!\is_string($tag)) {
5252
return [false, null, [], null];
5353
}
5454

5555
$decodedTags[$tag] = $tag;
5656
}
5757

5858
$expiration = $record[2];
59-
if (!is_int($expiration) && null !== $expiration) {
59+
if (!\is_int($expiration) && null !== $expiration) {
6060
return [false, null, [], null];
6161
}
6262

@@ -97,7 +97,7 @@ protected function storeItemInCache(PhpCacheItem $item, ?int $ttl): bool
9797
*/
9898
private function skipIfCli(): bool
9999
{
100-
return $this->skipOnCli && 'cli' === php_sapi_name();
100+
return $this->skipOnCli && 'cli' === \PHP_SAPI;
101101
}
102102

103103
public function getDirectValue(string $name): mixed

‎src/Adapter/Apcu/Tests/ApcuCachePoolTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Cache\Adapter\Apcu\Tests;
413

514
use Cache\Adapter\Apcu\ApcuCachePool;

‎src/Adapter/Apcu/Tests/Fixtures/apcu_functions.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Cache\Adapter\Apcu;
413

514
use Cache\Adapter\Apcu\Tests\ApcuFunctionStub;

‎src/Adapter/Apcu/Tests/IntegrationPoolTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IntegrationPoolTest extends BaseTest
2525

2626
public function createCachePool(): CacheItemPoolInterface
2727
{
28-
if (defined('HHVM_VERSION') || !function_exists('apcu_store') || (function_exists('apcu_enabled') && !apcu_enabled())) {
28+
if (\defined('HHVM_VERSION') || !\function_exists('apcu_store') || (\function_exists('apcu_enabled') && !apcu_enabled())) {
2929
$this->markTestSkipped();
3030
}
3131

‎src/Adapter/Apcu/Tests/IntegrationSimpleCachelTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IntegrationSimpleCachelTest extends BaseTest
1919
{
2020
public function createSimpleCache(): CacheInterface
2121
{
22-
if (defined('HHVM_VERSION') || !function_exists('apcu_store') || (function_exists('apcu_enabled') && !apcu_enabled())) {
22+
if (\defined('HHVM_VERSION') || !\function_exists('apcu_store') || (\function_exists('apcu_enabled') && !apcu_enabled())) {
2323
$this->markTestSkipped();
2424
}
2525

‎src/Adapter/Apcu/Tests/IntegrationTagTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IntegrationTagTest extends TaggableCachePoolTest
1919
{
2020
public function createCachePool(): TaggableCacheItemPoolInterface
2121
{
22-
if (defined('HHVM_VERSION') || !function_exists('apcu_store') || (function_exists('apcu_enabled') && !apcu_enabled())) {
22+
if (\defined('HHVM_VERSION') || !\function_exists('apcu_store') || (\function_exists('apcu_enabled') && !apcu_enabled())) {
2323
$this->markTestSkipped();
2424
}
2525

‎src/Adapter/Chain/CachePoolChain.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getItems(array $keys = []): iterable
118118
$hits = [];
119119
$loadedItems = [];
120120
$notFoundItems = [];
121-
$keysCount = count($keys);
121+
$keysCount = \count($keys);
122122
$poolResponded = false;
123123
foreach ($this->getPools() as $poolKey => $pool) {
124124
try {
@@ -154,7 +154,7 @@ public function getItems(array $keys = []): iterable
154154
if ([] !== $poolNotFoundItems) {
155155
$notFoundItems[$poolKey] = $poolNotFoundItems;
156156
}
157-
if (count($hits) === $keysCount) {
157+
if (\count($hits) === $keysCount) {
158158
break;
159159
}
160160
} catch (\Exception $e) {
@@ -199,14 +199,14 @@ private function prepareKeys(array $keys): array
199199
{
200200
$validatedKeys = [];
201201
foreach ($keys as $key) {
202-
if (!is_string($key)) {
203-
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given', get_debug_type($key)));
202+
if (!\is_string($key)) {
203+
throw new InvalidArgumentException(\sprintf('Cache key must be string, "%s" given', get_debug_type($key)));
204204
}
205205
if ('' === $key) {
206206
throw new InvalidArgumentException('Cache key cannot be an empty string');
207207
}
208208
if (preg_match('|[\{\}\(\)/\\\\\@\:]|', $key)) {
209-
throw new InvalidArgumentException(sprintf('Invalid key: "%s". The key contains one or more characters reserved for future extension: {}()/\@:', $key));
209+
throw new InvalidArgumentException(\sprintf('Invalid key: "%s". The key contains one or more characters reserved for future extension: {}()/\@:', $key));
210210
}
211211

212212
$validatedKeys["\0".$key] = $key;
@@ -482,7 +482,7 @@ private function handleException(int|string $poolKey, string $operation, \Except
482482

483483
$this->log(
484484
'warning',
485-
sprintf(
485+
\sprintf(
486486
'Removing pool "%s" from chain because it threw an exception when executing "%s"',
487487
$poolKey,
488488
$operation

‎src/Adapter/Common/AbstractCachePool.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ public function commit(): bool
275275
*/
276276
protected function validateKey(mixed $key): string
277277
{
278-
if (!is_string($key)) {
279-
$e = new InvalidArgumentException(sprintf(
278+
if (!\is_string($key)) {
279+
$e = new InvalidArgumentException(\sprintf(
280280
'Cache key must be string, "%s" given',
281-
gettype($key)
281+
\gettype($key)
282282
));
283283
$this->handleException($e, __FUNCTION__);
284284
}
@@ -287,7 +287,7 @@ protected function validateKey(mixed $key): string
287287
$this->handleException($e, __FUNCTION__);
288288
}
289289
if (preg_match('|[\{\}\(\)/\\\@\:]|', $key)) {
290-
$e = new InvalidArgumentException(sprintf(
290+
$e = new InvalidArgumentException(\sprintf(
291291
'Invalid key: "%s". The key contains one or more characters reserved for future extension: {}()/\@:',
292292
$key
293293
));
@@ -328,7 +328,7 @@ private function handleException(\Exception $e, string $function): never
328328

329329
$this->log($level, $e->getMessage(), ['exception' => $e]);
330330
if (!$e instanceof CacheException) {
331-
$e = new CachePoolException(sprintf('Exception thrown when executing "%s". ', $function), 0, $e);
331+
$e = new CachePoolException(\sprintf('Exception thrown when executing "%s". ', $function), 0, $e);
332332
}
333333

334334
throw $e;
@@ -489,7 +489,7 @@ public function setMultiple(iterable $values, int|\DateInterval|null $ttl = null
489489
$keys = [];
490490
$arrayValues = [];
491491
foreach ($values as $key => $value) {
492-
if (is_int($key)) {
492+
if (\is_int($key)) {
493493
$key = (string) $key;
494494
}
495495
$this->validateKey($key);

0 commit comments

Comments
 (0)