snappymail/plugins/cache-redis/Predis/Cluster/PredisStrategy.php
google-labs-jules[bot] 2548ed59da Fix PHP 8.4 implicit nullable parameter deprecations in Predis library
PHP 8.4 deprecates implicitly nullable parameter types. Parameters with a default value of `null` must now be explicitly marked as nullable (e.g., `?Type $var = null`).

This change updates the vendored `Predis` library in `plugins/cache-redis/` to comply with this requirement. It scans for function signatures like `Type $var = null` and updates them to `?Type $var = null`. This ensures compatibility with PHP 8.4 and PHP 8.5 while maintaining backward compatibility.

Affected files include `Predis` interfaces, connection classes, and command definitions.
Also updated PHPDoc `@method` annotations to reflect nullable types.
2026-01-16 15:11:52 +00:00

77 lines
1.6 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Cluster;
use Predis\Cluster\Distributor\DistributorInterface;
use Predis\Cluster\Distributor\HashRing;
/**
* Default cluster strategy used by Predis to handle client-side sharding.
*/
class PredisStrategy extends ClusterStrategy
{
protected $distributor;
/**
* @param DistributorInterface $distributor Optional distributor instance.
*/
public function __construct(?DistributorInterface $distributor = null)
{
parent::__construct();
$this->distributor = $distributor ?: new HashRing();
}
/**
* {@inheritdoc}
*/
public function getSlotByKey($key)
{
$key = $this->extractKeyTag($key);
$hash = $this->distributor->hash($key);
return $this->distributor->getSlot($hash);
}
/**
* {@inheritdoc}
*/
protected function checkSameSlotForKeys(array $keys)
{
if (!$count = count($keys)) {
return false;
}
$currentKey = $this->extractKeyTag($keys[0]);
for ($i = 1; $i < $count; ++$i) {
$nextKey = $this->extractKeyTag($keys[$i]);
if ($currentKey !== $nextKey) {
return false;
}
$currentKey = $nextKey;
}
return true;
}
/**
* {@inheritdoc}
*/
public function getDistributor()
{
return $this->distributor;
}
}