Skip to content

Commit

Permalink
fix: psr/cache >=2.0 ломал поддержку PHP 8.0
Browse files Browse the repository at this point in the history
Исправлено:

- ограничение psr/cache: ^1.0 для поддержки PHP 8.0.

Изменено:

- незначительные изменения кода в связи с обнаруженными ошибками и
  предупреждениями от PHPStan и PhpStorm;

- обновление friendsofphp/php-cs-fixer: с ^2.16 до ^3.0.
  • Loading branch information
webarchitect609 committed Aug 28, 2021
1 parent a360dd7 commit 28a976f
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.php_cs
/.php_cs.cache
/.php-cs-fixer.php
/.php-cs-fixer.cache
/.phpunit.result.cache
/build/
/composer.lock
Expand Down
44 changes: 44 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new Config)->setUsingCache(true)
->setRiskyAllowed(true)
->setRules(
[
'@PSR2' => true,
'psr_autoloading' => true,
'linebreak_after_opening_tag' => true,
'multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => true,
'no_useless_else' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'phpdoc_order' => true,
'pow_to_exponentiation' => true,
'random_api_migration' => true,
'align_multiline_comment' => true,
'phpdoc_types_order' => true,
'no_null_property_initialization' => true,
'no_unneeded_final_method' => true,
'no_unneeded_curly_braces' => true,
'no_superfluous_elseif' => true,
'trailing_comma_in_multiline' => true,
'no_unused_imports' => true,
'include' => true,
'array_syntax' => [
'syntax' => 'short',
],
]
)
->setFinder(
(Finder::create())->in(
[
__DIR__ . '/src/main',
__DIR__ . '/src/test',
]
)
->files()
->name('*.php')
);
45 changes: 0 additions & 45 deletions .php_cs.dist

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Change Log
==========

1.9.3
-----

### Исправлено:

- ограничение `psr/cache: ^1.0` для поддержки `PHP 8.0`.

### Изменено:

- незначительные изменения кода в связи с обнаруженными ошибками и предупреждениями от PHPStan и PhpStorm;
- обновление `friendsofphp/php-cs-fixer` с `^2.16` до `^3.0`.

1.9.2
-----

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
],
"require": {
"php": "^7.2 || ^8.0",
"psr/cache": "^1.0",
"psr/log": "^1.1",
"psr/simple-cache": "^1.0",
"symfony/cache-contracts": "^2.1",
"symfony/polyfill-php80": "^1.18",
"symfony/service-contracts": "^2.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
Expand All @@ -59,7 +60,7 @@
"@check:security"
],
"check:analyse": "vendor/bin/phpstan analyse --ansi --no-progress",
"check:code-style": "vendor/bin/php-cs-fixer fix --ansi --dry-run --diff --diff-format udiff",
"check:code-style": "vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",
"check:security": "@composer update --no-suggest --no-interaction --dry-run roave/security-advisories",
"check:test": "vendor/bin/phpunit --colors=always"
},
Expand Down
12 changes: 6 additions & 6 deletions dev-tools/php-cs-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fi
echo "EXTRA_ARGS: ${EXTRA_ARGS}"

vendor/bin/php-cs-fixer fix \
--config=.php_cs.dist \
--ansi \
--dry-run \
--stop-on-violation \
--using-cache=no \
--diff ${EXTRA_ARGS}
--config=.php-cs-fixer.dist.php \
--ansi \
--dry-run \
--stop-on-violation \
--using-cache=no \
--diff ${EXTRA_ARGS}
18 changes: 7 additions & 11 deletions src/main/AntiStampedeCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\NullLogger;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Service\ResetInterface;
use WebArch\BitrixCache\Traits\AbstractAdapterTrait;
use WebArch\BitrixCache\Traits\ContractsTrait;
Expand Down Expand Up @@ -42,7 +43,6 @@ class AntiStampedeCacheAdapter implements CacheInterface, CacheItemPoolInterface
*/
private $baseDir;

/** @noinspection PhpUnusedParameterInspection */
public function __construct(
string $path = Cache::DEFAULT_PATH,
int $defaultLifetime = Cache::DEFAULT_TTL,
Expand All @@ -68,8 +68,8 @@ static function ($key, $value, $isHit) {
$item->set($v[$k]);
$v = unpack('Ve/Nc', substr($k, 1, -1));
$metadata = $item->getMetadata();
$metadata[CacheItem::METADATA_EXPIRY] = $v['e'] + CacheItem::METADATA_EXPIRY_OFFSET;
$metadata[CacheItem::METADATA_CTIME] = $v['c'];
$metadata[ItemInterface::METADATA_EXPIRY] = $v['e'] + CacheItem::METADATA_EXPIRY_OFFSET;
$metadata[ItemInterface::METADATA_CTIME] = $v['c'];
$item->setMetadata($metadata);
}

Expand All @@ -95,15 +95,14 @@ static function ($deferred, $namespace, &$expiredIds) use ($getId, $defaultLifet
$expiredIds[] = $getId($key);
continue;
}
if (isset(($metadata = $item->newMetadata)[CacheItem::METADATA_TAGS])) {
unset($metadata[CacheItem::METADATA_TAGS]);
if (isset(($metadata = $item->newMetadata)[ItemInterface::METADATA_TAGS])) {
unset($metadata[ItemInterface::METADATA_TAGS]);
}
// `self` would be \Symfony\Contracts\Cache\ItemInterface, so there're no errors.
// For compactness, expiry and creation duration are packed in the key of an array, using magic numbers as separators
// @formatter:off
/**
* @noinspection PhpUndefinedClassConstantInspection
* @phpstan-ignore-next-line
*/
$byLifetime[$ttl][$getId($key)] = $metadata ? ["\x9D".pack('VN', (int) (0.1 + $metadata[self::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET), $metadata[self::METADATA_CTIME])."\x5F" => $item->value] : $item->value;
// @formatter:on
Expand Down Expand Up @@ -138,8 +137,7 @@ public function commit()
$e = $this->doSave($values, $lifetime);
} catch (Exception $e) {
}
/** @phpstan-ignore-next-line */
if (true === $e || [] === $e) {
if (true === $e) {
continue;
}
/** @phpstan-ignore-next-line */
Expand Down Expand Up @@ -179,8 +177,7 @@ public function commit()
$e = $this->doSave([$id => $v], $lifetime);
} catch (Exception $e) {
}
/** @phpstan-ignore-next-line */
if (true === $e || [] === $e) {
if (true === $e) {
continue;
}
$ok = false;
Expand Down Expand Up @@ -284,7 +281,6 @@ protected function doDelete(array $ids)
* @inheritDoc
*
* @return bool
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doClear(string $namespace)
Expand Down

0 comments on commit 28a976f

Please sign in to comment.