diff --git a/src/Redis.php b/src/Redis.php index 3b611bc..c5be1bc 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -5,6 +5,7 @@ namespace Laminas\Cache\Storage\Adapter; use Laminas\Cache\Exception; +use Laminas\Cache\Storage\Adapter\RedisResourceManager; use Laminas\Cache\Storage\Capabilities; use Laminas\Cache\Storage\ClearByNamespaceInterface; use Laminas\Cache\Storage\ClearByPrefixInterface; @@ -27,31 +28,23 @@ final class Redis extends AbstractAdapter implements { /** * Has this instance be initialized - * - * @var bool */ - protected $initialized = false; + private bool $initialized = false; /** * The redis resource manager - * - * @var null|RedisResourceManager */ - protected $resourceManager; + private ?RedisResourceManager $resourceManager = null; /** * The redis resource id - * - * @var null|string */ - protected $resourceId; + private ?string $resourceId = null; /** * The namespace prefix - * - * @var string */ - protected $namespacePrefix = ''; + private string $namespacePrefix = ''; /** * Create new Adapter for redis storage @@ -66,7 +59,7 @@ public function __construct($options = null) // reset initialized flag on update option(s) $initialized = &$this->initialized; - $this->getEventManager()->attach('option', function () use (&$initialized) { + $this->getEventManager()->attach('option', static function () use (&$initialized): void { $initialized = false; }); } @@ -185,9 +178,7 @@ protected function internalGetItems(array &$normalizedKeys) //combine the key => value pairs and remove all missing values return array_filter( array_combine($normalizedKeys, $results), - function ($value) { - return $value !== false; - } + static fn($value): bool => $value !== false ); } @@ -493,7 +484,7 @@ protected function internalGetCapabilities() $serializer = $resourceMgr->getLibOption($options->getResourceId(), RedisResource::OPT_SERIALIZER); $redisVersion = $resourceMgr->getMajorVersion($options->getResourceId()); $minTtl = version_compare((string) $redisVersion, '2', '<') ? 0 : 1; - $maxKeyLength = version_compare((string) $redisVersion, '3', '<') ? 255 : 512000000; + $maxKeyLength = version_compare((string) $redisVersion, '3', '<') ? 255 : 512_000_000; $supportedMetadata = $redisVersion >= 2 ? ['ttl'] : []; $this->capabilities = new Capabilities( diff --git a/src/RedisCluster.php b/src/RedisCluster.php index db116d0..cdee934 100644 --- a/src/RedisCluster.php +++ b/src/RedisCluster.php @@ -36,8 +36,7 @@ final class RedisCluster extends AbstractAdapter implements /** @var RedisClusterFromExtension|null */ private $resource; - /** @var string|null */ - private $namespacePrefix; + private ?string $namespacePrefix = null; /** @var RedisClusterResourceManagerInterface|null */ private $resourceManager; @@ -366,7 +365,7 @@ protected function internalGetCapabilities(): Capabilities 'staticTtl' => true, 'ttlPrecision' => 1, 'useRequestTime' => false, - 'maxKeyLength' => $redisVersionLessThanV3 ? 255 : 512000000, + 'maxKeyLength' => $redisVersionLessThanV3 ? 255 : 512_000_000, 'namespaceIsPrefix' => true, ] ); diff --git a/src/RedisClusterOptions.php b/src/RedisClusterOptions.php index 1542dd1..db048e7 100644 --- a/src/RedisClusterOptions.php +++ b/src/RedisClusterOptions.php @@ -34,32 +34,25 @@ final class RedisClusterOptions extends AdapterOptions public const OPT_COMPRESSION_LEVEL = 9; public const OPT_NULL_MULTIBULK_AS_NULL = 10; - /** @var string */ - protected $namespaceSeparator = ':'; + private string $namespaceSeparator = ':'; - /** @var string */ - private $name = ''; + private string $name = ''; - /** @var float */ - private $timeout = 1.0; + private float $timeout = 1.0; - /** @var float */ - private $readTimeout = 2.0; + private float $readTimeout = 2.0; - /** @var bool */ - private $persistent = false; + private bool $persistent = false; /** @psalm-var list */ - private $seeds = []; + private array $seeds = []; - /** @var string */ - private $version = ''; + private string $version = ''; /** @psalm-var array */ - private $libOptions = []; + private array $libOptions = []; - /** @var string */ - private $password = ''; + private string $password = ''; /** * @param array|Traversable|null|AdapterOptions $options diff --git a/src/RedisClusterResourceManager.php b/src/RedisClusterResourceManager.php index ef6dae5..7732a67 100644 --- a/src/RedisClusterResourceManager.php +++ b/src/RedisClusterResourceManager.php @@ -6,6 +6,7 @@ use Laminas\Cache\Exception\RuntimeException; use Laminas\Cache\Storage\Adapter\Exception\RedisRuntimeException; +use Laminas\Cache\Storage\Adapter\RedisClusterOptions; use Laminas\Cache\Storage\Plugin\PluginInterface; use Laminas\Cache\Storage\Plugin\Serializer; use Laminas\Cache\Storage\PluginCapableInterface; @@ -20,11 +21,10 @@ */ final class RedisClusterResourceManager implements RedisClusterResourceManagerInterface { - /** @var RedisClusterOptions */ - private $options; + private RedisClusterOptions $options; /** @psalm-var array */ - private $libraryOptions = []; + private array $libraryOptions = []; public function __construct(RedisClusterOptions $options) { diff --git a/src/RedisOptions.php b/src/RedisOptions.php index acd892b..3ce6161 100644 --- a/src/RedisOptions.php +++ b/src/RedisOptions.php @@ -5,6 +5,7 @@ namespace Laminas\Cache\Storage\Adapter; use Laminas\Cache\Exception; +use Laminas\Cache\Storage\Adapter\RedisResourceManager; use function sprintf; use function strlen; @@ -20,27 +21,20 @@ final class RedisOptions extends AdapterOptions */ protected $__prioritizedProperties__ = ['resource_manager', 'resource_id', 'server']; // @codingStandardsIgnoreEnd - /** * The namespace separator - * - * @var string */ - protected $namespaceSeparator = ':'; + private string $namespaceSeparator = ':'; /** * The redis resource manager - * - * @var null|RedisResourceManager */ - protected $resourceManager; + private ?RedisResourceManager $resourceManager = null; /** * The resource id of the resource manager - * - * @var string */ - protected $resourceId = 'default'; + private string $resourceId = 'default'; /** * Set namespace. diff --git a/src/RedisResourceManager.php b/src/RedisResourceManager.php index d123036..e271dce 100644 --- a/src/RedisResourceManager.php +++ b/src/RedisResourceManager.php @@ -29,10 +29,8 @@ final class RedisResourceManager { /** * Registered resources - * - * @var array */ - protected $resources = []; + private array $resources = []; /** * Check if a resource exists diff --git a/test/unit/RedisClusterOptionsFromIniTest.php b/test/unit/RedisClusterOptionsFromIniTest.php index 936700c..18d4620 100644 --- a/test/unit/RedisClusterOptionsFromIniTest.php +++ b/test/unit/RedisClusterOptionsFromIniTest.php @@ -13,8 +13,7 @@ final class RedisClusterOptionsFromIniTest extends TestCase { - /** @var string */ - private $seedsConfigurationFromIni; + private string $seedsConfigurationFromIni; public function testWillThrowExceptionOnMissingSeedsConfiguration(): void {