diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd6b815..05dacf2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog ## Unreleased +### Changed +- Switch to `static` closures + +### Fixed - Fixed Sentinel `getParameters()` executed on string configuration (#1649) - Fixed Sentinel discovery methods not catching `StreamInitException` on connection failure (#1650) diff --git a/examples/custom_cluster_distributor.php b/examples/custom_cluster_distributor.php index 681fe9c5..10cfbcf0 100644 --- a/examples/custom_cluster_distributor.php +++ b/examples/custom_cluster_distributor.php @@ -40,7 +40,7 @@ class NaiveDistributor implements DistributorInterface, HashGeneratorInterface public function remove($node) { - $this->nodes = array_filter($this->nodes, function ($n) use ($node) { + $this->nodes = array_filter($this->nodes, static function ($n) use ($node) { return $n !== $node; }); @@ -89,7 +89,7 @@ class NaiveDistributor implements DistributorInterface, HashGeneratorInterface } $options = [ - 'cluster' => function () { + 'cluster' => static function () { $distributor = new NaiveDistributor(); $strategy = new PredisStrategy($distributor); $cluster = new PredisCluster($strategy); diff --git a/examples/dispatcher_loop.php b/examples/dispatcher_loop.php index eda711c3..d61dd072 100644 --- a/examples/dispatcher_loop.php +++ b/examples/dispatcher_loop.php @@ -62,7 +62,7 @@ class EventsListener implements Countable $dispatcher->attachCallback('events', $events = new EventsListener()); // Attach a function to control the dispatcher loop termination with a message. -$dispatcher->attachCallback('control', function ($payload, $dispatcher) { +$dispatcher->attachCallback('control', static function ($payload, $dispatcher) { if ($payload === 'terminate_dispatcher') { $dispatcher->stop(); } diff --git a/examples/pipelining_commands.php b/examples/pipelining_commands.php index e9f9a9d3..4d4357c8 100644 --- a/examples/pipelining_commands.php +++ b/examples/pipelining_commands.php @@ -18,7 +18,7 @@ require __DIR__ . '/shared.php'; $client = new Predis\Client($single_server); -$responses = $client->pipeline(function ($pipe) { +$responses = $client->pipeline(static function ($pipe) { $pipe->flushdb(); $pipe->incrby('counter', 10); $pipe->incrby('counter', 30); diff --git a/examples/push_notifications.php b/examples/push_notifications.php index a95f8b74..cfe93ed5 100644 --- a/examples/push_notifications.php +++ b/examples/push_notifications.php @@ -19,7 +19,7 @@ require __DIR__ . '/shared.php'; $client = new Predis\Client($single_server + ['read_write_timeout' => 0, 'protocol' => 3]); // 2. Create push notifications consumer. Provides callback where current consumer subscribes to few channels before enter the loop. -$push = $client->push(function (ClientInterface $client) { +$push = $client->push(static function (ClientInterface $client) { $response = $client->subscribe('channel', 'control'); $status = ($response[2] === 1) ? 'OK' : 'FAILED'; echo "Channel subscription status: {$status}\n"; diff --git a/examples/push_notifications_dispatcher.php b/examples/push_notifications_dispatcher.php index e7435b47..2fd565f5 100644 --- a/examples/push_notifications_dispatcher.php +++ b/examples/push_notifications_dispatcher.php @@ -21,7 +21,7 @@ require __DIR__ . '/shared.php'; $client = new Predis\Client($single_server + ['read_write_timeout' => 0, 'protocol' => 3]); // 2. Create push notifications consumer. Provides callback where current consumer subscribes to few channels before enter the loop. -$push = $client->push(function (ClientInterface $client) { +$push = $client->push(static function (ClientInterface $client) { $response = $client->subscribe('channel', 'control'); $status = ($response[2] === 1) ? 'OK' : 'FAILED'; echo "Channel subscription status: {$status}\n"; diff --git a/examples/relay_pubsub_consumer.php b/examples/relay_pubsub_consumer.php index 2cc02c4c..dd6536d5 100644 --- a/examples/relay_pubsub_consumer.php +++ b/examples/relay_pubsub_consumer.php @@ -23,7 +23,7 @@ $pubsub = $client->pubSubLoop(); // When using Relay you cannot use foreach-loops to iterate // over messages instead use a callback function -$poorMansKafka = function ($message, $client) { +$poorMansKafka = static function ($message, $client) { switch ($message->kind) { case 'subscribe': echo "Subscribed to {$message->channel}", PHP_EOL; diff --git a/examples/replication_complex.php b/examples/replication_complex.php index 01dc5718..424e24f8 100644 --- a/examples/replication_complex.php +++ b/examples/replication_complex.php @@ -56,7 +56,7 @@ $options = [ 'commands' => [ 'hmgetall' => 'HashMultipleGetAll', ], - 'replication' => function () { + 'replication' => static function () { $strategy = new ReplicationStrategy(); $strategy->setScriptReadOnly(HashMultipleGetAll::BODY); diff --git a/examples/sharded_dispatcher_loop.php b/examples/sharded_dispatcher_loop.php index b5af8285..59047e97 100644 --- a/examples/sharded_dispatcher_loop.php +++ b/examples/sharded_dispatcher_loop.php @@ -74,7 +74,7 @@ class EventsListener implements Countable $dispatcher->attachCallback('{channels}_events', $events = new EventsListener()); // 6. Attach a function to control the dispatcher loop termination with a message. -$dispatcher->attachCallback('control', function ($payload, $dispatcher) { +$dispatcher->attachCallback('control', static function ($payload, $dispatcher) { if ($payload === 'terminate_dispatcher') { $dispatcher->stop(); } diff --git a/examples/transaction_using_cas.php b/examples/transaction_using_cas.php index dddfed3d..963f49dc 100644 --- a/examples/transaction_using_cas.php +++ b/examples/transaction_using_cas.php @@ -35,7 +35,7 @@ function zpop($client, $key) // which the client bails out with an exception. ]; - $client->transaction($options, function ($tx) use ($key, &$element) { + $client->transaction($options, static function ($tx) use ($key, &$element) { @[$element] = $tx->zrange($key, 0, 0); if (isset($element)) { diff --git a/src/Cluster/SlotMap.php b/src/Cluster/SlotMap.php index 7cd8b356..5e477245 100644 --- a/src/Cluster/SlotMap.php +++ b/src/Cluster/SlotMap.php @@ -87,7 +87,7 @@ class SlotMap implements ArrayAccess, IteratorAggregate, Countable { return array_reduce( $this->slotRanges, - function ($carry, $slotRange) { + static function ($carry, $slotRange) { return $carry + $slotRange->toArray(); }, [] @@ -102,7 +102,7 @@ class SlotMap implements ArrayAccess, IteratorAggregate, Countable public function getNodes() { return array_unique(array_map( - function ($slotRange) { + static function ($slotRange) { return $slotRange->getConnection(); }, $this->slotRanges @@ -192,7 +192,7 @@ class SlotMap implements ArrayAccess, IteratorAggregate, Countable return array_reduce( $intersections, - function ($carry, $slotRange) { + static function ($carry, $slotRange) { return $carry + $slotRange->toArray(); }, [] @@ -287,7 +287,7 @@ class SlotMap implements ArrayAccess, IteratorAggregate, Countable public function count() { return array_sum(array_map( - function ($slotRange) { + static function ($slotRange) { return $slotRange->count(); }, $this->slotRanges @@ -370,7 +370,7 @@ class SlotMap implements ArrayAccess, IteratorAggregate, Countable { usort( $slotRanges, - function (SlotRange $a, SlotRange $b) { + static function (SlotRange $a, SlotRange $b) { if ($a->getStart() == $b->getStart()) { return 0; } diff --git a/src/Command/PrefixableCommand.php b/src/Command/PrefixableCommand.php index fdad6900..87808422 100644 --- a/src/Command/PrefixableCommand.php +++ b/src/Command/PrefixableCommand.php @@ -33,7 +33,7 @@ abstract class PrefixableCommand extends Command implements PrefixableCommandInt public function applyPrefixForAllArguments(string $prefix): void { $this->setRawArguments( - array_map(function ($key) use ($prefix) { + array_map(static function ($key) use ($prefix) { return $prefix . $key; }, $this->getArguments()) ); diff --git a/src/Command/Redis/ACL.php b/src/Command/Redis/ACL.php index 5ca7e1f7..489148ff 100644 --- a/src/Command/Redis/ACL.php +++ b/src/Command/Redis/ACL.php @@ -43,7 +43,7 @@ class ACL extends RedisCommand // flatten Relay (RESP3) maps $return = []; - array_walk($data, function ($value, $key) use (&$return) { + array_walk($data, static function ($value, $key) use (&$return) { $return[] = $key; $return[] = $value; }); diff --git a/src/Command/Redis/BITFIELD_RO.php b/src/Command/Redis/BITFIELD_RO.php index d2344623..5b510c7c 100644 --- a/src/Command/Redis/BITFIELD_RO.php +++ b/src/Command/Redis/BITFIELD_RO.php @@ -34,7 +34,7 @@ class BITFIELD_RO extends RedisCommand if (array_key_exists(1, $arguments) && is_array($arguments[1])) { // Convert encoding => offset, into GET, encoding, offset - array_walk($arguments[1], function ($value, $key) use (&$processedArguments) { + array_walk($arguments[1], static function ($value, $key) use (&$processedArguments) { array_push($processedArguments, 'GET', $key, $value); }); } diff --git a/src/Command/Redis/HRANDFIELD.php b/src/Command/Redis/HRANDFIELD.php index ceeb5fd2..4822de60 100644 --- a/src/Command/Redis/HRANDFIELD.php +++ b/src/Command/Redis/HRANDFIELD.php @@ -44,7 +44,7 @@ class HRANDFIELD extends RedisCommand // flatten Relay (RESP3) maps $return = []; - array_walk_recursive($data, function ($value) use (&$return) { + array_walk_recursive($data, static function ($value) use (&$return) { $return[] = $value; }); diff --git a/src/Command/Redis/HSETEX.php b/src/Command/Redis/HSETEX.php index 6cc92e05..ae8b5179 100644 --- a/src/Command/Redis/HSETEX.php +++ b/src/Command/Redis/HSETEX.php @@ -58,7 +58,7 @@ class HSETEX extends RedisCommand $flatArray = []; // Convert key => value, into key, value - array_walk($arguments[1], function ($value, $key) use (&$flatArray) { + array_walk($arguments[1], static function ($value, $key) use (&$flatArray) { array_push($flatArray, $key, $value); }); diff --git a/src/Command/Redis/MSETEX.php b/src/Command/Redis/MSETEX.php index d3a88577..8dc73f08 100644 --- a/src/Command/Redis/MSETEX.php +++ b/src/Command/Redis/MSETEX.php @@ -29,7 +29,7 @@ class MSETEX extends PrefixableCommand { $processedArguments = [count(array_keys($arguments[0]))]; - array_walk($arguments[0], function ($value, $key) use (&$processedArguments) { + array_walk($arguments[0], static function ($value, $key) use (&$processedArguments) { array_push($processedArguments, $key, $value); }); diff --git a/src/Command/Redis/TDigest/TDIGESTBYRANK.php b/src/Command/Redis/TDigest/TDIGESTBYRANK.php index a89143c3..d5443a78 100644 --- a/src/Command/Redis/TDigest/TDIGESTBYRANK.php +++ b/src/Command/Redis/TDigest/TDIGESTBYRANK.php @@ -36,7 +36,7 @@ class TDIGESTBYRANK extends RedisCommand } // convert Relay (RESP3) constants to strings - return array_map(function ($value) { + return array_map(static function ($value) { if (is_string($value) || !is_float($value)) { return $value; } diff --git a/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php b/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php index 01cf684d..b910c7b5 100644 --- a/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php +++ b/src/Command/Redis/TDigest/TDIGESTBYREVRANK.php @@ -36,7 +36,7 @@ class TDIGESTBYREVRANK extends RedisCommand } // convert Relay (RESP3) constants to strings - return array_map(function ($value) { + return array_map(static function ($value) { if (is_string($value) || !is_float($value)) { return $value; } diff --git a/src/Command/Redis/TDigest/TDIGESTCDF.php b/src/Command/Redis/TDigest/TDIGESTCDF.php index 2402a987..5409fe6a 100644 --- a/src/Command/Redis/TDigest/TDIGESTCDF.php +++ b/src/Command/Redis/TDigest/TDIGESTCDF.php @@ -38,7 +38,7 @@ class TDIGESTCDF extends RedisCommand } // convert Relay (RESP3) constants to strings - return array_map(function ($value) { + return array_map(static function ($value) { if (is_string($value) || !is_float($value)) { return $value; } diff --git a/src/Command/Redis/TDigest/TDIGESTQUANTILE.php b/src/Command/Redis/TDigest/TDIGESTQUANTILE.php index 203103da..99bb33a8 100644 --- a/src/Command/Redis/TDigest/TDIGESTQUANTILE.php +++ b/src/Command/Redis/TDigest/TDIGESTQUANTILE.php @@ -36,7 +36,7 @@ class TDIGESTQUANTILE extends RedisCommand } // convert Relay (RESP3) constants to strings - return array_map(function ($value) { + return array_map(static function ($value) { if (is_string($value) || !is_float($value)) { return $value; } diff --git a/src/Command/Redis/Utils/CommandUtility.php b/src/Command/Redis/Utils/CommandUtility.php index 886e288e..49fedfbb 100644 --- a/src/Command/Redis/Utils/CommandUtility.php +++ b/src/Command/Redis/Utils/CommandUtility.php @@ -80,7 +80,7 @@ class CommandUtility { $array = []; - array_walk($dict, function ($value, $key) use (&$array) { + array_walk($dict, static function ($value, $key) use (&$array) { array_push($array, $key, $value); }); diff --git a/src/Command/Redis/VEMB.php b/src/Command/Redis/VEMB.php index d1368af9..ef0b4f69 100644 --- a/src/Command/Redis/VEMB.php +++ b/src/Command/Redis/VEMB.php @@ -52,7 +52,7 @@ class VEMB extends RedisCommand public function parseResponse($data) { if (!$this->isRaw) { - return array_map(function ($value) { return (float) $value; }, $data); + return array_map(static function ($value) { return (float) $value; }, $data); } $parsedData = []; diff --git a/src/Command/Redis/VLINKS.php b/src/Command/Redis/VLINKS.php index c67e15b4..bb2a81c8 100644 --- a/src/Command/Redis/VLINKS.php +++ b/src/Command/Redis/VLINKS.php @@ -58,7 +58,7 @@ class VLINKS extends RedisCommand if ($this->withScores) { foreach ($data as $key => $value) { if ($value === array_values($value)) { - $data[$key] = CommandUtility::arrayToDictionary($value, function ($key, $value) { + $data[$key] = CommandUtility::arrayToDictionary($value, static function ($key, $value) { return [$key, (float) $value]; }); } else { diff --git a/src/Command/Redis/VSIM.php b/src/Command/Redis/VSIM.php index fb0dafbb..303de55a 100644 --- a/src/Command/Redis/VSIM.php +++ b/src/Command/Redis/VSIM.php @@ -85,7 +85,7 @@ class VSIM extends RedisCommand { if ($this->withScores) { if ($data === array_values($data)) { - $data = CommandUtility::arrayToDictionary($data, function ($key, $value) { + $data = CommandUtility::arrayToDictionary($data, static function ($key, $value) { return [$key, (float) $value]; }); } diff --git a/src/Command/Redis/XINFO.php b/src/Command/Redis/XINFO.php index adc7a402..ad9d4686 100644 --- a/src/Command/Redis/XINFO.php +++ b/src/Command/Redis/XINFO.php @@ -69,12 +69,12 @@ class XINFO extends RedisCommand } if (isset($result['groups']) && is_array($result['groups'])) { - $result['groups'] = array_map(function ($group) { + $result['groups'] = array_map(static function ($group) { if ($group === array_values($group)) { $group = CommandUtility::arrayToDictionary($group, null, false); } if (isset($group['consumers'])) { - $group['consumers'] = array_map(function ($consumer) { + $group['consumers'] = array_map(static function ($consumer) { if ($consumer === array_values($consumer)) { $consumer = CommandUtility::arrayToDictionary($consumer, null, false); } diff --git a/src/Configuration/Option/Replication.php b/src/Configuration/Option/Replication.php index 5e7db95e..fd259c00 100644 --- a/src/Configuration/Option/Replication.php +++ b/src/Configuration/Option/Replication.php @@ -67,7 +67,7 @@ class Replication extends Aggregate switch ($description) { case 'sentinel': case 'redis-sentinel': - return function ($parameters, $options) { + return static function ($parameters, $options) { return new SentinelReplication($options->service, $parameters, $options->connections); }; @@ -90,7 +90,7 @@ class Replication extends Aggregate */ protected function getDefaultConnectionInitializer() { - return function ($parameters, $options) { + return static function ($parameters, $options) { $connection = new MasterSlaveReplication(); if ($options->autodiscovery) { diff --git a/src/Connection/Cluster/RedisCluster.php b/src/Connection/Cluster/RedisCluster.php index b824c911..99ff1bce 100644 --- a/src/Connection/Cluster/RedisCluster.php +++ b/src/Connection/Cluster/RedisCluster.php @@ -273,7 +273,7 @@ class RedisCluster extends AbstractAggregateConnection implements ClusterInterfa $command = RawCommand::create('CLUSTER', 'SLOTS'); - $doCallback = function () use (&$connection, $command) { + $doCallback = static function () use (&$connection, $command) { return $connection->executeCommand($command); }; diff --git a/src/Connection/Parameters.php b/src/Connection/Parameters.php index 0983d1eb..534c2d17 100644 --- a/src/Connection/Parameters.php +++ b/src/Connection/Parameters.php @@ -67,7 +67,7 @@ class Parameters implements ParametersInterface */ protected function filter(array $parameters) { - return array_filter($parameters, function ($value) { + return array_filter($parameters, static function ($value) { return $value !== null && $value !== ''; }); } diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index 501522c3..1a8bae4a 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -579,7 +579,7 @@ class SentinelReplication extends AbstractAggregateConnection implements Replica { $role = strtolower($role); $retry = $connection->getParameters()->retry; - $actualRole = $retry->callWithRetry(function () use ($connection) { + $actualRole = $retry->callWithRetry(static function () use ($connection) { return $connection->executeCommand(RawCommand::create('ROLE')); }); diff --git a/src/Consumer/PubSub/RelayConsumer.php b/src/Consumer/PubSub/RelayConsumer.php index b66b9a46..0fdaec5b 100644 --- a/src/Consumer/PubSub/RelayConsumer.php +++ b/src/Consumer/PubSub/RelayConsumer.php @@ -34,7 +34,7 @@ class RelayConsumer extends Consumer $command = $this->client->createCommand('subscribe', [ $channels, - function ($relay, $channel, $message) use ($callback) { + static function ($relay, $channel, $message) use ($callback) { $callback((object) [ 'kind' => is_null($message) ? self::SUBSCRIBE : self::MESSAGE, 'channel' => $channel, @@ -63,7 +63,7 @@ class RelayConsumer extends Consumer $command = $this->client->createCommand('psubscribe', [ $patterns, - function ($relay, $pattern, $channel, $message) use ($callback) { + static function ($relay, $pattern, $channel, $message) use ($callback) { $callback((object) [ 'kind' => is_null($message) ? self::PSUBSCRIBE : self::PMESSAGE, 'pattern' => $pattern, diff --git a/src/Monitor/Consumer.php b/src/Monitor/Consumer.php index 19c3a1f0..d34d3cbf 100644 --- a/src/Monitor/Consumer.php +++ b/src/Monitor/Consumer.php @@ -150,7 +150,7 @@ class Consumer implements Iterator $client = null; $event = $this->client->getConnection()->read(); - $callback = function ($matches) use (&$database, &$client) { + $callback = static function ($matches) use (&$database, &$client) { if (2 === $count = count($matches)) { // Redis <= 2.4 $database = (int) $matches[1]; diff --git a/src/Pipeline/Atomic.php b/src/Pipeline/Atomic.php index 1254e667..56f6ed95 100644 --- a/src/Pipeline/Atomic.php +++ b/src/Pipeline/Atomic.php @@ -71,7 +71,7 @@ class Atomic extends Pipeline $retry->callWithRetry(function () use ($connection, $commands) { $this->queuePipeline($connection, $commands); - }, function (Throwable $exception) { + }, static function (Throwable $exception) { if ($exception instanceof CommunicationException) { $exception->getConnection()->disconnect(); } @@ -152,9 +152,9 @@ class Atomic extends Pipeline { $retry = $connection->getParameters()->retry; - return $retry->callWithRetry(function () use ($connection, $command) { + return $retry->callWithRetry(static function () use ($connection, $command) { return $connection->executeCommand($command); - }, function (Throwable $e) { + }, static function (Throwable $e) { if ($e instanceof CommunicationException) { $e->getConnection()->disconnect(); } diff --git a/src/Pipeline/FireAndForget.php b/src/Pipeline/FireAndForget.php index 233b6faf..84cd5a26 100644 --- a/src/Pipeline/FireAndForget.php +++ b/src/Pipeline/FireAndForget.php @@ -36,7 +36,7 @@ class FireAndForget extends Pipeline } else { $this->writeToSingleNode($connection, $commands); } - }, function (Throwable $e) { + }, static function (Throwable $e) { if ($e instanceof CommunicationException) { $e->getConnection()->disconnect(); } diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index d4fdaa3a..cb456e54 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -352,7 +352,7 @@ abstract class PredisTestCase extends PHPUnit\Framework\TestCase if ($isSSL && $isCluster) { // For cluster SSL tests, use non-SSL cluster endpoints $endpoints = explode(',', constant('REDIS_CLUSTER_ENDPOINTS')); - $parameters = array_map(function (string $elem) { + $parameters = array_map(static function (string $elem) { return 'tcp://' . $elem; }, $endpoints); } elseif ($isSSL) { @@ -792,7 +792,7 @@ abstract class PredisTestCase extends PHPUnit\Framework\TestCase ); $scheme = $this->isSSLTest() ? 'tls' : 'tcp'; - return array_map(function (string $elem) use ($scheme) { + return array_map(static function (string $elem) use ($scheme) { return "{$scheme}://" . $elem; }, $endpoints); } @@ -806,7 +806,7 @@ abstract class PredisTestCase extends PHPUnit\Framework\TestCase { $endpoints = explode(',', constant('REDIS_SENTINEL_ENDPOINTS')); - return array_map(function (string $elem) { + return array_map(static function (string $elem) { return "tcp://{$elem}"; }, $endpoints); } diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index c7cb134a..625c2a44 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -1224,7 +1224,7 @@ class ClientTest extends PredisTestCase $callable ->expects($this->once()) ->method('__invoke') - ->willReturnCallback(function ($tx) { $tx->ping(); }); + ->willReturnCallback(static function ($tx) { $tx->ping(); }); $client = new Client($connection); $client->transaction($options, $callable); @@ -1523,7 +1523,7 @@ class ClientTest extends PredisTestCase public function testStandaloneNodeRetryCommandExecutionOnTimeoutException(): void { $retries = 0; - $mockDisconnect = function () use (&$retries) { + $mockDisconnect = static function () use (&$retries) { $streamConnection = new StreamConnection(new Parameters([ 'retry' => new Retry(new ExponentialBackoff(1000, 10000), 3), ])); @@ -1566,8 +1566,8 @@ class ClientTest extends PredisTestCase // Retry used to wrap callback around, so we can count retries $retry = new Retry(new ExponentialBackoff(100, 1000), 3); $retriesCount = 0; - $retryWrapperFunc = function (callable $do, ?callable $fail = null) use ($retry, &$retriesCount) { - $failWrapperFunc = function (Exception $e) use (&$retriesCount, $fail) { + $retryWrapperFunc = static function (callable $do, ?callable $fail = null) use ($retry, &$retriesCount) { + $failWrapperFunc = static function (Exception $e) use (&$retriesCount, $fail) { ++$retriesCount; $fail($e); }; @@ -1621,7 +1621,7 @@ class ClientTest extends PredisTestCase } $retries = 0; - $mockDisconnect = function () use (&$retries) { + $mockDisconnect = static function () use (&$retries) { $streamConnection = new StreamConnection(new Parameters([ 'retry' => new Retry(new ExponentialBackoff(1000, 10000), 3), ])); diff --git a/tests/Predis/Cluster/PredisStrategyTest.php b/tests/Predis/Cluster/PredisStrategyTest.php index 091d0c7a..e1e0ee95 100644 --- a/tests/Predis/Cluster/PredisStrategyTest.php +++ b/tests/Predis/Cluster/PredisStrategyTest.php @@ -514,7 +514,7 @@ class PredisStrategyTest extends PredisTestCase ]; if (isset($type)) { - $commands = array_filter($commands, function (string $expectedType) use ($type) { + $commands = array_filter($commands, static function (string $expectedType) use ($type) { return $expectedType === $type; }); } diff --git a/tests/Predis/Cluster/RedisStrategyTest.php b/tests/Predis/Cluster/RedisStrategyTest.php index 8606ba93..9eaf9a45 100644 --- a/tests/Predis/Cluster/RedisStrategyTest.php +++ b/tests/Predis/Cluster/RedisStrategyTest.php @@ -537,7 +537,7 @@ class RedisStrategyTest extends PredisTestCase ]; if (isset($type)) { - $commands = array_filter($commands, function (string $expectedType) use ($type) { + $commands = array_filter($commands, static function (string $expectedType) use ($type) { return $expectedType === $type; }); } diff --git a/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php b/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php index 8293d7d9..6414c16e 100644 --- a/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php +++ b/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php @@ -34,13 +34,13 @@ class HybridSearchQueryTest extends TestCase return [ 'with default configs' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -50,13 +50,13 @@ class HybridSearchQueryTest extends TestCase ], 'with RANGE vector search' => [ (new HybridSearchQuery(RangeVectorSearchConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (RangeVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->radius(5) @@ -66,19 +66,19 @@ class HybridSearchQueryTest extends TestCase ], 'with COMBINE config - RRF' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) ->ef(10); }) - ->buildCombineConfig(function (RRFCombineConfig $config) { + ->buildCombineConfig(static function (RRFCombineConfig $config) { $config ->window(5) ->rrfConstant(10); @@ -87,19 +87,19 @@ class HybridSearchQueryTest extends TestCase ], 'with COMBINE config - LINEAR' => [ (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) ->ef(10); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(0.2) ->beta(0.3); @@ -108,13 +108,13 @@ class HybridSearchQueryTest extends TestCase ], 'with LOAD' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -125,13 +125,13 @@ class HybridSearchQueryTest extends TestCase ], 'with GROUPBY' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -148,13 +148,13 @@ class HybridSearchQueryTest extends TestCase ], 'with APPLY' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -165,13 +165,13 @@ class HybridSearchQueryTest extends TestCase ], 'with SORTBY' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -182,13 +182,13 @@ class HybridSearchQueryTest extends TestCase ], 'with FILTER' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -199,13 +199,13 @@ class HybridSearchQueryTest extends TestCase ], 'with LIMIT' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -216,13 +216,13 @@ class HybridSearchQueryTest extends TestCase ], 'with PARAMS' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -233,13 +233,13 @@ class HybridSearchQueryTest extends TestCase ], 'with EXPLAINSCORE' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -250,13 +250,13 @@ class HybridSearchQueryTest extends TestCase ], 'with TIMEOUT' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -267,13 +267,13 @@ class HybridSearchQueryTest extends TestCase ], 'with WITHCURSOR' => [ (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) diff --git a/tests/Predis/Command/Argument/Search/HybridSearch/SearchConfigTest.php b/tests/Predis/Command/Argument/Search/HybridSearch/SearchConfigTest.php index 0f4bd7d7..54b8cfac 100644 --- a/tests/Predis/Command/Argument/Search/HybridSearch/SearchConfigTest.php +++ b/tests/Predis/Command/Argument/Search/HybridSearch/SearchConfigTest.php @@ -33,7 +33,7 @@ class SearchConfigTest extends TestCase } if ($type) { - $this->assertEquals($config, $config->buildScorerConfig(function (ScorerConfig $scorerConfig) use ($type) { + $this->assertEquals($config, $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) use ($type) { $scorerConfig->type($type); })); } diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index 65fab12e..41f8c513 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -123,7 +123,7 @@ class KeyPrefixProcessorTest extends PredisTestCase ->expects($this->once()) ->method('__invoke') ->with($command, 'prefix:') - ->willReturnCallback(function ($command, $prefix) { + ->willReturnCallback(static function ($command, $prefix) { $command->setRawArguments(['prefix:key', 'value']); }); @@ -148,7 +148,7 @@ class KeyPrefixProcessorTest extends PredisTestCase ->expects($this->once()) ->method('__invoke') ->with($command, 'prefix:') - ->willReturnCallback(function ($command, $prefix) { + ->willReturnCallback(static function ($command, $prefix) { $command->setRawArguments(['prefix:key', 'value']); }); diff --git a/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php b/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php index 259d7315..cc7150a1 100644 --- a/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php +++ b/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php @@ -53,13 +53,13 @@ class FTHYBRID_Test extends PredisCommandTestCase { $command = $this->getCommand(); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { - $config->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildSearchConfig(static function (SearchConfig $config) { + $config->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_DISMAX); }) ->query('*'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('vector', '$vector') ->k(5) @@ -105,14 +105,14 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red} @color:{green}') - ->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_TFIDF); }); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) ->params([ @@ -135,14 +135,14 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red} @color:{green}') - ->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_TFIDF); }); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) ->params([ @@ -165,11 +165,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red} @color:{green}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) ->params([ @@ -197,11 +197,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red} @color:{green}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) ->params([ @@ -229,17 +229,17 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes') - ->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_TFIDF); }); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(1) ->beta(0); @@ -271,17 +271,17 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->assertEquals($expectedResultsTFIDF, $response['results']); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes') - ->buildScorerConfig(function (ScorerConfig $scorerConfig) { + ->buildScorerConfig(static function (ScorerConfig $scorerConfig) { $scorerConfig->type(ScorerConfig::TYPE_BM25); }); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config->vector('@embedding', '$vector'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(1) ->beta(0); @@ -326,11 +326,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->k(3) @@ -356,11 +356,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{missing}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector') ->filter('@price:[15 16] @size:[10 11]'); @@ -392,12 +392,12 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes') ->as('search_score'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -429,11 +429,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->k(3) @@ -468,19 +468,19 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes') ->as('search_score'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1) ->as('vsim_score'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(0.5) ->beta(0.5) @@ -524,19 +524,19 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('shoes') ->as('search_score'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1) ->as('vsim_score'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(0.5) ->beta(0.5) @@ -568,11 +568,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{none}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector') ->k(3); @@ -591,11 +591,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->assertEquals($expected_results, $response['results']); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{none}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->k(3) @@ -628,11 +628,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery(RangeVectorSearchConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{none}'); }) - ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (RangeVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -651,11 +651,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->assertEquals($expected_results, $response['results']); $query = (new HybridSearchQuery(RangeVectorSearchConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{none}'); }) - ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (RangeVectorSearchConfig $config) { $config ->vector('@embedding-hnsw', '$vector') ->radius(2) @@ -689,15 +689,15 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(0.5) ->beta(0.5); @@ -717,15 +717,15 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->assertEquals($expected_results, $response['results']); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, RRFCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) - ->buildCombineConfig(function (RRFCombineConfig $config) { + ->buildCombineConfig(static function (RRFCombineConfig $config) { $config ->window(3) ->rrfConstant(0.5); @@ -758,15 +758,15 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red|green|black}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) - ->buildCombineConfig(function (LinearCombineConfig $config) { + ->buildCombineConfig(static function (LinearCombineConfig $config) { $config ->alpha(0.5) ->beta(0.5); @@ -802,11 +802,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -861,11 +861,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red|green|black}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -897,11 +897,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 5); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{$color_criteria}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -953,11 +953,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red|green}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -1019,11 +1019,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red|green}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -1087,11 +1087,11 @@ class FTHYBRID_Test extends PredisCommandTestCase $this->generateData($redis, 10); $query = (new HybridSearchQuery()) - ->buildSearchConfig(function (SearchConfig $config) { + ->buildSearchConfig(static function (SearchConfig $config) { $config ->query('@color:{red|green}'); }) - ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { + ->buildVectorSearchConfig(static function (KNNVectorSearchConfig $config) { $config ->vector('@embedding', '$vector'); }) @@ -1143,7 +1143,7 @@ class FTHYBRID_Test extends PredisCommandTestCase $mergedItems = array_merge($mergedItems, $items); } - $client->pipeline(function (ClientContextInterface $pipe) use ($mergedItems) { + $client->pipeline(static function (ClientContextInterface $pipe) use ($mergedItems) { for ($i = 0; $i < count($mergedItems); ++$i) { [$vec, $description] = $mergedItems[$i]; diff --git a/tests/Predis/Command/RedisFactoryTest.php b/tests/Predis/Command/RedisFactoryTest.php index 0b7a6c66..f60ac68a 100644 --- a/tests/Predis/Command/RedisFactoryTest.php +++ b/tests/Predis/Command/RedisFactoryTest.php @@ -244,7 +244,7 @@ class RedisFactoryTest extends PredisTestCase ->method('process') ->with($this->isInstanceOf('Predis\Command\CommandInterface')) ->willReturnCallback( - function (CommandInterface $cmd) use (&$argsRef) { + static function (CommandInterface $cmd) use (&$argsRef) { $cmd->setRawArguments($argsRef = array_map('strtoupper', $cmd->getArguments())); } ); diff --git a/tests/Predis/Command/Utils/CommandUtilityTest.php b/tests/Predis/Command/Utils/CommandUtilityTest.php index d4442f29..07479616 100644 --- a/tests/Predis/Command/Utils/CommandUtilityTest.php +++ b/tests/Predis/Command/Utils/CommandUtilityTest.php @@ -104,14 +104,14 @@ class CommandUtilityTest extends PredisTestCase 'with callback applied' => [ ['key1', ['key2', ['key3', '0.1']]], ['key1' => ['key2' => ['key3' => 0.1]]], - function ($key, $value) { + static function ($key, $value) { return [$key, (float) $value]; }, ], 'with non-recursive approach' => [ ['key1', ['key2', ['key3', '0.1']]], ['key1' => ['key2', ['key3', '0.1']]], - function ($key, $value) { + static function ($key, $value) { return [$key, (float) $value]; }, false, diff --git a/tests/Predis/Configuration/Option/AggregateTest.php b/tests/Predis/Configuration/Option/AggregateTest.php index 5c28e526..6349f819 100644 --- a/tests/Predis/Configuration/Option/AggregateTest.php +++ b/tests/Predis/Configuration/Option/AggregateTest.php @@ -301,7 +301,7 @@ class AggregateTest extends PredisTestCase $factory ->expects($this->exactly(3)) ->method('create') - ->willReturnCallback(function () use ($connectionClass) { + ->willReturnCallback(static function () use ($connectionClass) { return new $connectionClass(); }); diff --git a/tests/Predis/Configuration/OptionsTest.php b/tests/Predis/Configuration/OptionsTest.php index 2382dab1..1cbf359a 100644 --- a/tests/Predis/Configuration/OptionsTest.php +++ b/tests/Predis/Configuration/OptionsTest.php @@ -218,7 +218,7 @@ class OptionsTest extends PredisTestCase ->expects($this->never()) ->method('autoload'); - spl_autoload_register($autoload = function ($class) use ($trigger) { + spl_autoload_register($autoload = static function ($class) use ($trigger) { $trigger->autoload($class); }, true, false); diff --git a/tests/Predis/Connection/Cluster/RedisClusterTest.php b/tests/Predis/Connection/Cluster/RedisClusterTest.php index 26359ae9..915293b5 100644 --- a/tests/Predis/Connection/Cluster/RedisClusterTest.php +++ b/tests/Predis/Connection/Cluster/RedisClusterTest.php @@ -154,13 +154,13 @@ class RedisClusterTest extends PredisTestCase $connection1 ->expects($this->once()) ->method('connect') - ->willReturnCallback(function () use (&$connect1) { + ->willReturnCallback(static function () use (&$connect1) { $connect1 = true; }); $connection1 ->expects($this->any()) ->method('isConnected') - ->willReturnCallback(function () use (&$connect1) { + ->willReturnCallback(static function () use (&$connect1) { return $connect1; }); @@ -168,13 +168,13 @@ class RedisClusterTest extends PredisTestCase $connection2 ->expects($this->once()) ->method('connect') - ->willReturnCallback(function () use (&$connect2) { + ->willReturnCallback(static function () use (&$connect2) { $connect2 = true; }); $connection2 ->expects($this->any()) ->method('isConnected') - ->willReturnCallback(function () use (&$connect2) { + ->willReturnCallback(static function () use (&$connect2) { return $connect2; }); diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index 5f4c8e4a..4ac2a126 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -482,7 +482,7 @@ class FactoryTest extends PredisTestCase $parameters = new Parameters(['scheme' => 'foobar']); $factory = new Factory(); - $initializer = function ($parameters) use ($connectionClass) { + $initializer = static function ($parameters) use ($connectionClass) { return new $connectionClass($parameters); }; diff --git a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php index 5ffdd6c8..7383c053 100644 --- a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php @@ -995,7 +995,7 @@ class MasterSlaveReplicationTest extends PredisTestCase $replication ->getReplicationStrategy() - ->setCommandReadOnly('exists', function ($cmd) { + ->setCommandReadOnly('exists', static function ($cmd) { [$arg1] = $cmd->getArguments(); return $arg1 === 'foo'; diff --git a/tests/Predis/Consumer/PubSub/ConsumerTest.php b/tests/Predis/Consumer/PubSub/ConsumerTest.php index 3cab06c4..c6553caf 100644 --- a/tests/Predis/Consumer/PubSub/ConsumerTest.php +++ b/tests/Predis/Consumer/PubSub/ConsumerTest.php @@ -99,7 +99,7 @@ class ConsumerTest extends PredisTestCase $this->equalTo('psubscribe'), $this->equalTo('ssubscribe') )) - ->willReturnCallback(function ($id, $args) use ($commands) { + ->willReturnCallback(static function ($id, $args) use ($commands) { return $commands->create($id, $args); }); diff --git a/tests/Predis/Consumer/PubSub/DispatcherLoopTest.php b/tests/Predis/Consumer/PubSub/DispatcherLoopTest.php index 4cdf7361..27586ce7 100644 --- a/tests/Predis/Consumer/PubSub/DispatcherLoopTest.php +++ b/tests/Predis/Consumer/PubSub/DispatcherLoopTest.php @@ -71,7 +71,7 @@ class DispatcherLoopTest extends PredisTestCase $this->equalTo('01:argument'), $this->equalTo('01:quit') ), $dispatcher) - ->willReturnCallback(function ($arg, $dispatcher) { + ->willReturnCallback(static function ($arg, $dispatcher) { if ($arg === '01:quit') { $dispatcher->stop(); } @@ -141,7 +141,7 @@ class DispatcherLoopTest extends PredisTestCase ->expects($this->exactly(1)) ->method('__invoke') ->with($this->equalTo('arg:prefixed'), $dispatcher) - ->willReturnCallback(function ($arg, $dispatcher) { + ->willReturnCallback(static function ($arg, $dispatcher) { $dispatcher->stop(); }); diff --git a/tests/Predis/Pipeline/AtomicTest.php b/tests/Predis/Pipeline/AtomicTest.php index 8b44bc5f..03dddb14 100644 --- a/tests/Predis/Pipeline/AtomicTest.php +++ b/tests/Predis/Pipeline/AtomicTest.php @@ -337,7 +337,7 @@ class AtomicTest extends PredisTestCase $pipeline = new Atomic(new Client($mockConnection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->ping(); $pipe->ping(); $pipe->ping(); @@ -359,7 +359,7 @@ class AtomicTest extends PredisTestCase ['replication' => 'predis'] ); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', "bar\r\nbaz"); $pipe->get('foo'); }); diff --git a/tests/Predis/Pipeline/FireAndForgetTest.php b/tests/Predis/Pipeline/FireAndForgetTest.php index ed580aea..1ec85d9c 100644 --- a/tests/Predis/Pipeline/FireAndForgetTest.php +++ b/tests/Predis/Pipeline/FireAndForgetTest.php @@ -127,7 +127,7 @@ class FireAndForgetTest extends PredisTestCase $pipeline = new FireAndForget(new Client($mockConnection)); - $pipeline->execute(function (Pipeline $pipe) { + $pipeline->execute(static function (Pipeline $pipe) { $pipe->ping(); $pipe->ping(); $pipe->ping(); @@ -177,7 +177,7 @@ class FireAndForgetTest extends PredisTestCase $pipeline = new FireAndForget(new Client($mockClusterConnection)); - $pipeline->execute(function (Pipeline $pipe) { + $pipeline->execute(static function (Pipeline $pipe) { $pipe->ping(); $pipe->ping(); $pipe->ping(); @@ -227,7 +227,7 @@ class FireAndForgetTest extends PredisTestCase $pipeline = new FireAndForget(new Client($mockReplicationConnection)); - $pipeline->execute(function (Pipeline $pipe) { + $pipeline->execute(static function (Pipeline $pipe) { $pipe->ping(); $pipe->ping(); $pipe->ping(); @@ -267,7 +267,7 @@ class FireAndForgetTest extends PredisTestCase ['replication' => 'predis'] ); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', "bar\r\nbaz"); $pipe->get('foo'); }); diff --git a/tests/Predis/Pipeline/PipelineTest.php b/tests/Predis/Pipeline/PipelineTest.php index b80f868d..94f9d5fd 100644 --- a/tests/Predis/Pipeline/PipelineTest.php +++ b/tests/Predis/Pipeline/PipelineTest.php @@ -373,7 +373,7 @@ class PipelineTest extends PredisTestCase $test = $this; $pipeline = new Pipeline(new Client()); - $callable = function (Pipeline $pipe) use ($test, $pipeline) { + $callable = static function (Pipeline $pipe) use ($test, $pipeline) { $test->assertSame($pipeline, $pipe); $pipe->flushPipeline(false); }; @@ -403,7 +403,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client()); - $pipeline->execute(function (Pipeline $pipe) { + $pipeline->execute(static function (Pipeline $pipe) { $pipe->execute(); }); } @@ -446,7 +446,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->echo('one'); $pipe->echo('two'); $pipe->echo('three'); @@ -475,7 +475,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); try { - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->echo('one'); $pipe->echo('two'); throw new ClientException('TEST'); @@ -532,7 +532,7 @@ class PipelineTest extends PredisTestCase $connection = new StreamConnection($parameters, $mockStreamFactory); $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->ping(); $pipe->ping(); $pipe->ping(); @@ -590,7 +590,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->set('key', 'value'); $pipe->set('key', 'value'); $pipe->set('key', 'value'); @@ -669,7 +669,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->set('key', 'value'); $pipe->set('key', 'value'); $pipe->set('key', 'value'); @@ -742,7 +742,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->set('key', 'value'); $pipe->set('key', 'value'); $pipe->set('key', 'value'); @@ -801,7 +801,7 @@ class PipelineTest extends PredisTestCase $pipeline = new Pipeline(new Client($connection)); - $responses = $pipeline->execute(function (Pipeline $pipe) { + $responses = $pipeline->execute(static function (Pipeline $pipe) { $pipe->set('key', 'value'); $pipe->set('key', 'value'); $pipe->set('key', 'value'); @@ -854,7 +854,7 @@ class PipelineTest extends PredisTestCase { $client = $this->getClient(); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', 'bar'); $pipe->get('foo'); }); @@ -871,7 +871,7 @@ class PipelineTest extends PredisTestCase $oob = null; $client = $this->getClient(); - $results = $client->pipeline(function (Pipeline $pipe) use (&$oob) { + $results = $client->pipeline(static function (Pipeline $pipe) use (&$oob) { $pipe->set('foo', 'bar'); $oob = $pipe->getClient()->echo('oob message'); $pipe->get('foo'); @@ -892,7 +892,7 @@ class PipelineTest extends PredisTestCase $client = $this->getClient(); try { - $client->pipeline(function (Pipeline $pipe) { + $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', 'bar'); throw new ClientException('TEST'); }); @@ -915,7 +915,7 @@ class PipelineTest extends PredisTestCase $client = $this->getClient(); try { - $client->pipeline(function (Pipeline $pipe) { + $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', 'bar'); // LPUSH on a string key fails, but won't stop // the pipeline to send the commands. @@ -938,7 +938,7 @@ class PipelineTest extends PredisTestCase { $client = $this->getClient([], ['exceptions' => false]); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', 'bar'); $pipe->lpush('foo', 'bar'); // LPUSH on a string key fails. $pipe->get('foo'); @@ -959,7 +959,7 @@ class PipelineTest extends PredisTestCase { $client = $this->getClient(); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', 'bar'); $pipe->set('bar', 'foo'); $pipe->set('baz', 'baz'); @@ -995,7 +995,7 @@ class PipelineTest extends PredisTestCase $this->expectException(TimeoutException::class); - $client->pipeline(function (Pipeline $pipe) use (&$retries) { + $client->pipeline(static function (Pipeline $pipe) use (&$retries) { $pipe->incr('test_key'); $pipe->blpop('foo', 3); }); @@ -1021,7 +1021,7 @@ class PipelineTest extends PredisTestCase $this->expectException(TimeoutException::class); - $client->pipeline(function (Pipeline $pipe) use (&$retries) { + $client->pipeline(static function (Pipeline $pipe) use (&$retries) { ++$retries; $pipe->blpop('foo', 3); }); @@ -1041,7 +1041,7 @@ class PipelineTest extends PredisTestCase ['replication' => 'predis'] ); - $results = $client->pipeline(function (Pipeline $pipe) { + $results = $client->pipeline(static function (Pipeline $pipe) { $pipe->set('foo', "bar\r\nbaz"); $pipe->get('foo'); }); @@ -1078,7 +1078,7 @@ class PipelineTest extends PredisTestCase */ protected function getReadCallback(): callable { - return function (CommandInterface $command) { + return static function (CommandInterface $command) { if (($id = $command->getId()) !== 'ECHO') { throw new InvalidArgumentException("Expected ECHO, got {$id}"); } diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index 18f448e6..95563a0d 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/tests/Predis/Replication/ReplicationStrategyTest.php @@ -311,7 +311,7 @@ class ReplicationStrategyTest extends PredisTestCase $commands = $this->getCommandFactory(); $strategy = new ReplicationStrategy(); - $strategy->setCommandReadOnly('SET', function (CommandInterface $command) { + $strategy->setCommandReadOnly('SET', static function (CommandInterface $command) { return $command->getArgument(1) === true; }); @@ -362,7 +362,7 @@ class ReplicationStrategyTest extends PredisTestCase ->method('getScript') ->willReturn($script = 'return true'); - $strategy->setScriptReadOnly($script, function (CommandInterface $command) { + $strategy->setScriptReadOnly($script, static function (CommandInterface $command) { return $command->getArgument(2) === true; }); @@ -557,7 +557,7 @@ class ReplicationStrategyTest extends PredisTestCase ]; if (isset($type)) { - $commands = array_filter($commands, function (string $expectedType) use ($type) { + $commands = array_filter($commands, static function (string $expectedType) use ($type) { return $expectedType === $type; }); } diff --git a/tests/Predis/Retry/RetryTest.php b/tests/Predis/Retry/RetryTest.php index 7f04c52b..658edec8 100644 --- a/tests/Predis/Retry/RetryTest.php +++ b/tests/Predis/Retry/RetryTest.php @@ -39,7 +39,7 @@ class RetryTest extends TestCase $retry = new Retry($backoffStrategy, $retries); $retriesCount = 0; - $callable = function () use (&$retriesCount, $retries) { + $callable = static function () use (&$retriesCount, $retries) { if ($retriesCount >= $retries) { return; } @@ -82,7 +82,7 @@ class RetryTest extends TestCase throw new StreamInitException(); }; - $failCallable = function () use (&$retriesCount) { + $failCallable = static function () use (&$retriesCount) { ++$retriesCount; }; diff --git a/tests/Predis/SSLTest.php b/tests/Predis/SSLTest.php index 2d466790..6bfcf318 100644 --- a/tests/Predis/SSLTest.php +++ b/tests/Predis/SSLTest.php @@ -185,7 +185,7 @@ class SSLTest extends PredisTestCase // Remove AUTH $defaultParameters = $this->getDefaultParametersArray(); - $trimmedParameters = array_map(function (string $parameter) { + $trimmedParameters = array_map(static function (string $parameter) { return explode('?', $parameter)[0]; }, $defaultParameters); diff --git a/tests/Predis/Transaction/MultiExecTest.php b/tests/Predis/Transaction/MultiExecTest.php index cb1b42a2..e219f24a 100644 --- a/tests/Predis/Transaction/MultiExecTest.php +++ b/tests/Predis/Transaction/MultiExecTest.php @@ -138,7 +138,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback($expected, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->echo('one'); $tx->echo('two'); $tx->echo('three'); @@ -161,7 +161,7 @@ class MultiExecTest extends PredisTestCase $exception = null; try { - $tx->echo('foo')->execute(function ($tx) { + $tx->echo('foo')->execute(static function ($tx) { $tx->echo('bar'); }); } catch (Exception $ex) { @@ -182,7 +182,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback(null, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { // NOOP }); @@ -203,7 +203,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback(null, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->exec(); }); @@ -221,7 +221,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback(null, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->discard(); }); @@ -239,7 +239,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback(null, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->set('foo', 'bar'); $tx->get('foo'); $tx->discard(); @@ -260,7 +260,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback($expected, $commands); $tx = $this->getMockedTransaction($callback); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->echo('before DISCARD'); $tx->discard(); $tx->echo('after DISCARD'); @@ -312,7 +312,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback($expected, $txCommands, $casCommands); $tx = $this->getMockedTransaction($callback, $options); - $responses = $tx->execute(function ($tx) { + $responses = $tx->execute(static function ($tx) { $tx->get('foo'); $tx->get('hoge'); }); @@ -363,7 +363,7 @@ class MultiExecTest extends PredisTestCase $tx = $this->getMockedTransaction($callback, $options); $test = $this; - $responses = $tx->execute(function ($tx) use ($test) { + $responses = $tx->execute(static function ($tx) use ($test) { $tx->watch('foobar'); $response1 = $tx->get('foo'); @@ -394,7 +394,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback([], $txCommands, $casCommands); $tx = $this->getMockedTransaction($callback, $options); - $tx->execute(function ($tx) { + $tx->execute(static function ($tx) { $tx->multi(); }); @@ -413,7 +413,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback([], $txCommands, $casCommands); $tx = $this->getMockedTransaction($callback, $options); - $tx->execute(function ($tx) { + $tx->execute(static function ($tx) { $tx->get('foo'); $tx->set('hoge', 'piyo'); }); @@ -457,7 +457,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback($expected, $txCommands, $casCommands); $tx = $this->getMockedTransaction($callback, $options); - $responses = $tx->execute(function (MultiExec $tx) use ($signal, &$attempts) { + $responses = $tx->execute(static function (MultiExec $tx) use ($signal, &$attempts) { $tx->get('foo'); if ($attempts > 0) { @@ -484,7 +484,7 @@ class MultiExecTest extends PredisTestCase $callback = $this->getExecuteCallback(); $tx = $this->getMockedTransaction($callback); - $tx->execute(function ($tx) { + $tx->execute(static function ($tx) { $tx->echo('!!ABORT!!'); }); } @@ -503,7 +503,7 @@ class MultiExecTest extends PredisTestCase $responses = null; try { - $responses = $tx->execute(function (MultiExec $tx) { + $responses = $tx->execute(static function (MultiExec $tx) { $tx->set('foo', 'bar'); $tx->get('foo'); @@ -532,7 +532,7 @@ class MultiExecTest extends PredisTestCase $responses = null; try { - $responses = $tx->execute(function (MultiExec $tx) { + $responses = $tx->execute(static function (MultiExec $tx) { $tx->set('foo', 'bar'); $tx->echo('ERR Invalid operation'); $tx->get('foo'); @@ -550,7 +550,7 @@ class MultiExecTest extends PredisTestCase */ public function testProperlyDiscardsTransactionAfterServerExceptionInBlock(): void { - $connection = $this->getMockedConnection(function (CommandInterface $command) { + $connection = $this->getMockedConnection(static function (CommandInterface $command) { switch ($command->getId()) { case 'MULTI': return true; @@ -596,7 +596,7 @@ class MultiExecTest extends PredisTestCase { $expected = ['before', new Response\Error('ERR simulated error'), 'after']; - $connection = $this->getMockedConnection(function (CommandInterface $command) use ($expected) { + $connection = $this->getMockedConnection(static function (CommandInterface $command) use ($expected) { switch ($command->getId()) { case 'MULTI': return true; @@ -632,7 +632,7 @@ class MultiExecTest extends PredisTestCase $expected = ['before', new Response\Error('ERR simulated error'), 'after']; - $connection = $this->getMockedConnection(function (CommandInterface $command) use ($expected) { + $connection = $this->getMockedConnection(static function (CommandInterface $command) use ($expected) { switch ($command->getId()) { case 'MULTI': return true; @@ -659,7 +659,7 @@ class MultiExecTest extends PredisTestCase $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessage('ERR simulated failure on EXEC'); - $connection = $this->getMockedConnection(function (CommandInterface $command) { + $connection = $this->getMockedConnection(static function (CommandInterface $command) { switch ($command->getId()) { case 'MULTI': return true; @@ -718,7 +718,7 @@ class MultiExecTest extends PredisTestCase $tx = new MultiExec(new Client($mockConnection)); - $responses = $tx->execute(function (MultiExec $tx) { + $responses = $tx->execute(static function (MultiExec $tx) { $tx->set('key', 'value'); $tx->set('key', 'value'); $tx->set('key', 'value'); @@ -740,7 +740,7 @@ class MultiExecTest extends PredisTestCase $exception = null; try { - $client->transaction(function (MultiExec $tx) { + $client->transaction(static function (MultiExec $tx) { $tx->set('foo', 'bar'); throw new RuntimeException('TEST'); }); @@ -762,7 +762,7 @@ class MultiExecTest extends PredisTestCase $value = (string) rand(); try { - $client->transaction(function (MultiExec $tx) use ($value) { + $client->transaction(static function (MultiExec $tx) use ($value) { $tx->set('foo', 'bar'); $tx->lpush('foo', 'bar'); $tx->set('foo', $value); @@ -783,7 +783,7 @@ class MultiExecTest extends PredisTestCase { $client = $this->getClient([], ['exceptions' => false]); - $responses = $client->transaction(function (MultiExec $tx) { + $responses = $client->transaction(static function (MultiExec $tx) { $tx->set('foo', 'bar'); $tx->lpush('foo', 'bar'); $tx->echo('foobar'); @@ -802,7 +802,7 @@ class MultiExecTest extends PredisTestCase { $client = $this->getClient([], ['exceptions' => false]); - $responses = $client->transaction(function (MultiExec $tx) { + $responses = $client->transaction(static function (MultiExec $tx) { $tx->set('foo', 'bar'); $tx->lpush('foo', 'bar'); $tx->echo('foobar'); @@ -821,7 +821,7 @@ class MultiExecTest extends PredisTestCase { $client = $this->getClient(); - $responses = $client->transaction(function (MultiExec $tx) { + $responses = $client->transaction(static function (MultiExec $tx) { $tx->set('foo', 'bar'); $tx->discard(); $tx->set('hoge', 'piyo'); @@ -844,7 +844,7 @@ class MultiExecTest extends PredisTestCase $client2 = $this->getClient(); try { - $client1->transaction(['watch' => 'sentinel'], function ($tx) use ($client2) { + $client1->transaction(['watch' => 'sentinel'], static function ($tx) use ($client2) { $tx->set('sentinel', 'client1'); $tx->get('sentinel'); $client2->set('sentinel', 'client2'); @@ -869,7 +869,7 @@ class MultiExecTest extends PredisTestCase $client2 = $this->getClient(); try { - $client1->transaction(['watch' => 'sentinel'], function ($tx) use ($client2) { + $client1->transaction(['watch' => 'sentinel'], static function ($tx) use ($client2) { $tx->set('sentinel', 'client1'); $tx->get('sentinel'); $client2->set('sentinel', 'client2'); @@ -893,7 +893,7 @@ class MultiExecTest extends PredisTestCase $client->set('foo', 'bar'); $options = ['watch' => 'foo', 'cas' => true]; - $responses = $client->transaction($options, function ($tx) { + $responses = $client->transaction($options, static function ($tx) { $tx->watch('foobar'); $foo = $tx->get('foo'); @@ -911,7 +911,7 @@ class MultiExecTest extends PredisTestCase $client->set('foo', 'bar'); $options = ['watch' => 'foo', 'cas' => true, 'retry' => 1]; - $responses = $client->transaction($options, function ($tx) use ($client2, &$hijack) { + $responses = $client->transaction($options, static function ($tx) use ($client2, &$hijack) { $foo = $tx->get('foo'); $tx->multi(); @@ -940,7 +940,7 @@ class MultiExecTest extends PredisTestCase { $redis = $this->getClient(); - $response = $redis->transaction(function (MultiExec $tx) { + $response = $redis->transaction(static function (MultiExec $tx) { $tx->set('{foo}foo', 'value'); $tx->set('{foo}bar', 'value'); $tx->set('{foo}baz', 'value'); @@ -964,7 +964,7 @@ class MultiExecTest extends PredisTestCase 'To be able to execute a transaction against cluster, all commands should operate on the same hash slot' ); - $redis->transaction(function (MultiExec $tx) { + $redis->transaction(static function (MultiExec $tx) { $tx->set('foo_bar_baz', 'value'); $tx->set('{foo}bar', 'value'); $tx->set('{foo}baz', 'value'); @@ -982,7 +982,7 @@ class MultiExecTest extends PredisTestCase $redis = $this->getClient(); $options = ['cas' => true, 'watch' => ['{foo}foo', '{foo}bar', '{foo}baz']]; - $response = $redis->transaction($options, function (MultiExec $tx) { + $response = $redis->transaction($options, static function (MultiExec $tx) { $tx->multi(); $tx->set('{foo}foo', 'value'); $tx->set('{foo}bar', 'value'); @@ -1003,7 +1003,7 @@ class MultiExecTest extends PredisTestCase $redis = $this->getClient(); $options = ['cas' => true, 'watch' => ['{foo}foo', '{foo}bar', '{foo}baz']]; - $response = $redis->transaction($options, function (MultiExec $tx) { + $response = $redis->transaction($options, static function (MultiExec $tx) { $tx->multi(); $tx->set('{foo}foo', 'value'); $tx->set('{foo}bar', 'value'); @@ -1028,7 +1028,7 @@ class MultiExecTest extends PredisTestCase $this->expectException(TransactionException::class); $this->expectExceptionMessage('WATCHed keys should point to the same hash slot'); - $redis->transaction($options, function (MultiExec $tx) { + $redis->transaction($options, static function (MultiExec $tx) { $tx->multi(); $tx->set('{foo}foo', 'value'); $tx->set('{foo}bar', 'value'); @@ -1052,7 +1052,7 @@ class MultiExecTest extends PredisTestCase 'To be able to execute a transaction against cluster, all commands should operate on the same hash slot' ); - $redis->transaction($options, function (MultiExec $tx) { + $redis->transaction($options, static function (MultiExec $tx) { $tx->multi(); $tx->set('{foo}foo', 'value'); $tx->set('{foo}bar', 'value'); @@ -1128,7 +1128,7 @@ class MultiExecTest extends PredisTestCase ): callable { $multi = $watch = $abort = false; - return function (CommandInterface $command) use (&$expected, &$commands, &$cas, &$multi, &$watch, &$abort) { + return static function (CommandInterface $command) use (&$expected, &$commands, &$cas, &$multi, &$watch, &$abort) { $cmd = $command->getId(); if ($multi || $cmd === 'MULTI') { @@ -1208,7 +1208,7 @@ class MultiExecTest extends PredisTestCase */ protected static function commandsToIDs(array $commands): array { - return array_map(function ($cmd) { return $cmd->getId(); }, $commands); + return array_map(static function ($cmd) { return $cmd->getId(); }, $commands); } /** diff --git a/tests/Predis/Transaction/Strategy/NodeConnectionStrategyTest.php b/tests/Predis/Transaction/Strategy/NodeConnectionStrategyTest.php index 59b9c9cf..32d5cd17 100644 --- a/tests/Predis/Transaction/Strategy/NodeConnectionStrategyTest.php +++ b/tests/Predis/Transaction/Strategy/NodeConnectionStrategyTest.php @@ -68,7 +68,7 @@ class NodeConnectionStrategyTest extends TestCase $this->mockConnection ->expects($this->once()) ->method('executeCommand') - ->with($this->callback(function ($command) { + ->with($this->callback(static function ($command) { return $command->getId() === 'UNWATCH'; })) ->willReturn('OK'); @@ -95,7 +95,7 @@ class NodeConnectionStrategyTest extends TestCase $this->mockConnection ->expects($this->exactly(4)) ->method('executeCommand') - ->with($this->callback(function ($command) { + ->with($this->callback(static function ($command) { return $command->getId() === 'UNWATCH'; })) ->willReturnOnConsecutiveCalls(