From ca19564b7f2a673a631d64332269a7e1e5bc6819 Mon Sep 17 00:00:00 2001 From: DevSviat Date: Sat, 24 Oct 2026 16:24:35 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20Rector=20=E2=80=94=20=D1=81=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D0=BA=D1=81=D0=B8=D1=87=D0=BD=D1=96=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0;=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D1=96=D1=8F=201.0.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ті самі 19 правил, що в ядрі форку (rector.php): array() → [], list() → [], isset() ? : → ??, стрілкові функції, intval(...) замість \x27intval\x27, new X()->m(), типи private-констант, catch без невикористаної змінної. Сигнатур, видимості й типів властивостей не міняє. --- Extenders/VariantsCacheInvalidator.php | 2 +- Helpers/ProductsHelper.php | 6 ++-- Init/module.json | 2 +- Services/CacheTags.php | 14 ++++----- Services/RedisCacheService.php | 40 ++++++++++++-------------- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Extenders/VariantsCacheInvalidator.php b/Extenders/VariantsCacheInvalidator.php index be85878..153b554 100644 --- a/Extenders/VariantsCacheInvalidator.php +++ b/Extenders/VariantsCacheInvalidator.php @@ -46,7 +46,7 @@ public function onVariantsDelete($output, $ids): void private function bumpByVariantIds(array $variantIds): void { - $variantIds = array_values(array_filter(array_map('intval', $variantIds))); + $variantIds = array_values(array_filter(array_map(intval(...), $variantIds))); if (empty($variantIds)) { return; } diff --git a/Helpers/ProductsHelper.php b/Helpers/ProductsHelper.php index c364c97..ba14e7b 100644 --- a/Helpers/ProductsHelper.php +++ b/Helpers/ProductsHelper.php @@ -111,7 +111,7 @@ public function attachImages(array $products) if (empty($products) || !$this->redisCache->isEnabled()) { return parent::attachImages($products); } - $productIds = array_map('intval', array_keys($products)); + $productIds = array_map(intval(...), array_keys($products)); sort($productIds); if (count($productIds) > 20) { return parent::attachImages($products); @@ -165,7 +165,7 @@ public function attachMainImages(array $products) if (count($imageIds) > 50 || count($products) > 50) { return parent::attachMainImages($products); } - $tags = $this->imageCacheTags(array_map('intval', array_keys($products))); + $tags = $this->imageCacheTags(array_map(intval(...), array_keys($products))); $key = $this->redisCache->makeVersionedKey('products_attach_main_images', $tags, [$imageIds]); $cached = $this->redisCache->get($key); @@ -253,7 +253,7 @@ private function imageCacheTags(array $productIds): array // Сортуємо: понад чотири теги вектор версій згортається в md5, тож // порядок став би значущим і той самий набір товарів під різним // сортуванням лістингу давав би різні ключі. - $productIds = array_values(array_unique(array_map('intval', $productIds))); + $productIds = array_values(array_unique(array_map(intval(...), $productIds))); sort($productIds); $tags = [CacheTags::PRODUCTS_ALL]; diff --git a/Init/module.json b/Init/module.json index 3000950..e816142 100644 --- a/Init/module.json +++ b/Init/module.json @@ -1,6 +1,6 @@ { "Okay": "4.5.3", - "version": "1.0.10", + "version": "1.0.11", "name": "Redis cache", "description": "Кешування Redis", "vendor": { diff --git a/Services/CacheTags.php b/Services/CacheTags.php index 1458c5b..6f35c8b 100644 --- a/Services/CacheTags.php +++ b/Services/CacheTags.php @@ -4,13 +4,13 @@ final class CacheTags { - public const PRODUCT_VERSION = 'pver:'; - public const PRODUCTS_ALL = 'pall:global'; - public const PRODUCTS_LIST = 'plist:global'; - public const CATEGORIES = 'cver:global'; - public const BRANDS = 'bver:global'; - public const AUTHORS_BLOG = 'aver:global'; - public const MONEY = 'mver:global'; + public const string PRODUCT_VERSION = 'pver:'; + public const string PRODUCTS_ALL = 'pall:global'; + public const string PRODUCTS_LIST = 'plist:global'; + public const string CATEGORIES = 'cver:global'; + public const string BRANDS = 'bver:global'; + public const string AUTHORS_BLOG = 'aver:global'; + public const string MONEY = 'mver:global'; public static function product(int $productId): string { diff --git a/Services/RedisCacheService.php b/Services/RedisCacheService.php index ab055ef..04e0242 100644 --- a/Services/RedisCacheService.php +++ b/Services/RedisCacheService.php @@ -6,7 +6,7 @@ class RedisCacheService { - private const VERSION_KEY_PREFIX = 'helpers:ver:'; + private const string VERSION_KEY_PREFIX = 'helpers:ver:'; private Settings $settings; private $client = null; @@ -19,29 +19,29 @@ class RedisCacheService * з TTL, тож запис без нього зробив би кеш невиселюваним — і тиск пішов * би на лічильники версій, виселення яких «воскрешає» старі дані. */ - private const MIN_TTL = 60; + private const int MIN_TTL = 60; /** Понад стільки тегів вектор версій згортається в хеш. */ - private const MAX_INLINE_TAGS = 4; + private const int MAX_INLINE_TAGS = 4; /** Скільки протухле значення ще можна віддавати, поки йде перерахунок. */ - private const SWR_GRACE = 3600; + private const int SWR_GRACE = 3600; /** Замок на перерахунок; переживає час самого перерахунку з запасом. */ - private const SWR_LOCK_TTL = 60; + private const int SWR_LOCK_TTL = 60; /** * Конверти лежать під власним іменем. Інакше відкат модуля віддав би * конверт старому коду, який чекає на голе значення, — і це не помилка * кешу, а TypeError у викликача. */ - private const SWR_NAME_SUFFIX = ':swr'; + private const string SWR_NAME_SUFFIX = ':swr'; /** @var array ключі, перерахунок яких уже заплановано в цьому запиті */ private array $refreshing = []; /** Вікно схлопування повторних bump одного тега, секунди. */ - private const BUMP_COLLAPSE_WINDOW = 1.0; + private const float BUMP_COLLAPSE_WINDOW = 1.0; /** * Скільки не торкатись Redis після провалу з'єднання. @@ -51,16 +51,16 @@ class RedisCacheService * запитами цю ціну платить кожен запит, тобто сайт формально живий і * фактично лежить. */ - private const BREAKER_TTL = 10; + private const int BREAKER_TTL = 10; /** * Стеля списку недоставлених bump. Довший простій дешевше й надійніше * закрити повним скиданням кешу, ніж тягнути список без краю. */ - private const PENDING_BUMPS_BYTES = 16384; + private const int PENDING_BUMPS_BYTES = 16384; /** Мітка «лік втрачено»: на відновленні скидаємо кеш цілком. */ - private const PENDING_OVERFLOW = '*'; + private const string PENDING_OVERFLOW = '*'; private array $helperTtlCache = []; private array $versionMemo = []; @@ -283,7 +283,7 @@ private function authenticateRedis(object $redis, ?string $username, ?string $pa if (self::$authSupportsTwoArgs) { return (bool) $redis->auth($user, $passStr); } - } catch (\ReflectionException $e) { + } catch (\ReflectionException) { // fallthrough } if (!method_exists($redis, 'rawCommand')) { @@ -326,9 +326,7 @@ protected function connectBare(bool $applyKeyPrefix = true, bool $persistent = f $redis->setOption($optReadTimeout, 0.5); } if (!$this->authenticateRedis($redis, $config['username'], $config['auth'])) { - if ($this->lastError === null) { - $this->lastError = 'Redis auth failed'; - } + $this->lastError ??= 'Redis auth failed'; return null; } // Безумовно: у persistent-з'єднанні обраний номер БД лишається від @@ -381,7 +379,7 @@ public function testConnection(bool $allowWhenDisabled = false): bool $this->lastError = $e->getMessage(); return false; } finally { - try { $client->close(); } catch (\Throwable $e) {} + try { $client->close(); } catch (\Throwable) {} } } @@ -405,7 +403,7 @@ public function flushAll(): bool return false; } finally { - try { $client->close(); } catch (\Throwable $e) {} + try { $client->close(); } catch (\Throwable) {} } } @@ -452,7 +450,7 @@ private function getContext(): array if ($sl->hasService(\Okay\Core\Languages::class)) { $langId = (int) $sl->getService(\Okay\Core\Languages::class)->getLangId(); } - } catch (\Throwable $e) {} + } catch (\Throwable) {} $currencyId = isset($_SESSION['currency_id']) ? (int) $_SESSION['currency_id'] : 0; $groupId = 0; @@ -468,7 +466,7 @@ private function getContext(): array } } } - } catch (\Throwable $e) {} + } catch (\Throwable) {} $this->context = ['lang' => $langId ?? 0, 'currency' => $currencyId, 'group' => $groupId]; return $this->context; @@ -535,7 +533,7 @@ public function version(string $tag): int public function versions(array $tags): array { - $tags = array_values(array_unique(array_filter(array_map('strval', $tags)))); + $tags = array_values(array_unique(array_filter(array_map(strval(...), $tags)))); if ($tags === []) { return []; } @@ -746,7 +744,7 @@ protected function now(): float private function dropClient(): void { if ($this->client !== null) { - try { $this->client->close(); } catch (\Throwable $e) {} + try { $this->client->close(); } catch (\Throwable) {} } $this->client = null; @@ -996,7 +994,7 @@ public function get(string $key) public function mGet(array $keys): array { - $keys = array_values(array_filter(array_map('strval', $keys), static fn($k) => $k !== '')); + $keys = array_values(array_filter(array_map(strval(...), $keys), static fn($k) => $k !== '')); if ($keys === []) { return []; }