Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply PHP 7.4 syntax and typed property #47

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
});
}
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions src/RedisCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]
);
Expand Down
25 changes: 9 additions & 16 deletions src/RedisClusterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<non-empty-string> */
private $seeds = [];
private array $seeds = [];

/** @var string */
private $version = '';
private string $version = '';

/** @psalm-var array<positive-int,mixed> */
private $libOptions = [];
private array $libOptions = [];

/** @var string */
private $password = '';
private string $password = '';

/**
* @param array|Traversable|null|AdapterOptions $options
Expand Down
6 changes: 3 additions & 3 deletions src/RedisClusterResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,11 +21,10 @@
*/
final class RedisClusterResourceManager implements RedisClusterResourceManagerInterface
{
/** @var RedisClusterOptions */
private $options;
private RedisClusterOptions $options;

/** @psalm-var array<positive-int,mixed> */
private $libraryOptions = [];
private array $libraryOptions = [];

public function __construct(RedisClusterOptions $options)
{
Expand Down
14 changes: 4 additions & 10 deletions src/RedisOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/RedisResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ final class RedisResourceManager
{
/**
* Registered resources
*
* @var array
*/
protected $resources = [];
private array $resources = [];

/**
* Check if a resource exists
Expand Down
3 changes: 1 addition & 2 deletions test/unit/RedisClusterOptionsFromIniTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

final class RedisClusterOptionsFromIniTest extends TestCase
{
/** @var string */
private $seedsConfigurationFromIni;
private string $seedsConfigurationFromIni;

public function testWillThrowExceptionOnMissingSeedsConfiguration(): void
{
Expand Down