From 113145f3065b8f34da2e09359f403e4db213b136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Tue, 17 Jan 2023 14:49:39 -0800 Subject: [PATCH] more code formatting --- .php-cs-fixer.dist.php | 3 +- src/Client.php | 18 +++------ src/Cluster/ClusterStrategy.php | 3 -- src/Command/Redis/ZUNIONSTORE.php | 2 +- .../Replication/SentinelReplication.php | 2 +- .../Connection/Cluster/RedisClusterTest.php | 40 +++++++++---------- 6 files changed, 28 insertions(+), 40 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 48860219..0c9e048f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -18,11 +18,12 @@ return (new PhpCsFixer\Config) 'phpdoc_separation' => false, 'phpdoc_annotation_without_dot' => false, 'no_superfluous_phpdoc_tags' => false, + 'no_unneeded_curly_braces' => false, 'global_namespace_import' => true, 'yoda_style' => false, 'single_line_throw' => false, 'concat_space' => ['spacing' => 'one'], - 'increment_style' => ['style' => 'post'], + 'increment_style' => false, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/src/Client.php b/src/Client.php index e764060e..a6b05537 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,7 +13,6 @@ namespace Predis; use ArrayIterator; - use InvalidArgumentException; use IteratorAggregate; use Predis\Command\CommandInterface; @@ -45,7 +44,7 @@ use Traversable; */ class Client implements ClientInterface, IteratorAggregate { - const VERSION = '2.1.1'; + public const VERSION = '2.1.1'; /** @var OptionsInterface */ private $options; @@ -62,8 +61,8 @@ class Client implements ClientInterface, IteratorAggregate */ public function __construct($parameters = null, $options = null) { - $this->options = static::createOptions($options ?? new Options); - $this->connection = static::createConnection($this->options, $parameters ?? new Parameters); + $this->options = static::createOptions($options ?? new Options()); + $this->connection = static::createConnection($this->options, $parameters ?? new Parameters()); $this->commands = $this->options->commands; } @@ -72,9 +71,8 @@ class Client implements ClientInterface, IteratorAggregate * * @param array|OptionsInterface $options Set of client options * - * @throws InvalidArgumentException - * * @return OptionsInterface + * @throws InvalidArgumentException */ protected static function createOptions($options) { @@ -108,9 +106,8 @@ class Client implements ClientInterface, IteratorAggregate * @param OptionsInterface $options Client options container * @param mixed $parameters Connection parameters * - * @throws InvalidArgumentException - * * @return ConnectionInterface + * @throws InvalidArgumentException */ protected static function createConnection(OptionsInterface $options, $parameters) { @@ -337,9 +334,8 @@ class Client implements ClientInterface, IteratorAggregate * @param CommandInterface $command Redis command that generated the error. * @param ErrorResponseInterface $response Instance of the error response. * - * @throws ServerException - * * @return mixed + * @throws ServerException */ protected function onErrorResponse(CommandInterface $command, ErrorResponseInterface $response) { @@ -387,11 +383,9 @@ class Client implements ClientInterface, IteratorAggregate return $this->$initializer($arg0, $arg1); - // @codeCoverageIgnoreStart default: return $this->$initializer($this, $argv); } - // @codeCoverageIgnoreEnd } /** diff --git a/src/Cluster/ClusterStrategy.php b/src/Cluster/ClusterStrategy.php index 60ba57c0..61278c74 100644 --- a/src/Cluster/ClusterStrategy.php +++ b/src/Cluster/ClusterStrategy.php @@ -23,9 +23,6 @@ abstract class ClusterStrategy implements StrategyInterface { protected $commands; - /** - * - */ public function __construct() { $this->commands = $this->getDefaultCommands(); diff --git a/src/Command/Redis/ZUNIONSTORE.php b/src/Command/Redis/ZUNIONSTORE.php index ea14611c..0d213c75 100644 --- a/src/Command/Redis/ZUNIONSTORE.php +++ b/src/Command/Redis/ZUNIONSTORE.php @@ -50,7 +50,7 @@ class ZUNIONSTORE extends RedisCommand public function setArguments(array $arguments) { // support old `$options` array for backwards compatibility - if (! isset($arguments[3]) && (isset($arguments[2]['weights']) || isset($arguments[2]['aggregate']))) { + if (!isset($arguments[3]) && (isset($arguments[2]['weights']) || isset($arguments[2]['aggregate']))) { $options = array_pop($arguments); array_push($arguments, $options['weights'] ?? []); array_push($arguments, $options['aggregate'] ?? 'sum'); diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index feba381f..896c7d9c 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -273,7 +273,7 @@ class SentinelReplication implements ReplicationInterface // don't leak password from between configurations // https://github.com/predis/predis/pull/807/#discussion_r985764770 - if (! isset($parameters['password'])) { + if (!isset($parameters['password'])) { $parameters['password'] = null; } diff --git a/tests/Predis/Connection/Cluster/RedisClusterTest.php b/tests/Predis/Connection/Cluster/RedisClusterTest.php index acdeb2c1..fbadbb35 100644 --- a/tests/Predis/Connection/Cluster/RedisClusterTest.php +++ b/tests/Predis/Connection/Cluster/RedisClusterTest.php @@ -19,9 +19,6 @@ use Predis\Connection; use Predis\Response; use PredisTestCase; -/** - * - */ class RedisClusterTest extends PredisTestCase { /** @@ -1306,22 +1303,22 @@ class RedisClusterTest extends PredisTestCase /** * @medium * @group disconnected - * @group slow + * @group slow */ public function testRetryCommandSuccessOnClusterDownErrors() { - $clusterDownError= new Response\Error('CLUSTERDOWN') ; + $clusterDownError = new Response\Error('CLUSTERDOWN'); - $command = Command\RawCommand::create('get', 'node:1001'); + $command = Command\RawCommand::create('get', 'node:1001'); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); $connection1->expects($this->exactly(3)) ->method('executeCommand') ->with($command) ->will($this->onConsecutiveCalls( - $clusterDownError, - $clusterDownError, - 'foobar')); + $clusterDownError, + $clusterDownError, + 'foobar')); $cluster = new RedisCluster(new Connection\Factory()); $cluster->useClusterSlots(false); @@ -1334,14 +1331,14 @@ class RedisClusterTest extends PredisTestCase /** * @medium * @group disconnected - * @group slow + * @group slow */ public function testRetryCommandFailureOnClusterDownErrors() { $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessage('CLUSTERDOWN'); - $clusterDownError= new Response\Error('CLUSTERDOWN') ; + $clusterDownError = new Response\Error('CLUSTERDOWN'); $command = Command\RawCommand::create('get', 'node:1001'); @@ -1350,11 +1347,10 @@ class RedisClusterTest extends PredisTestCase ->method('executeCommand') ->with($command) ->will($this->onConsecutiveCalls( - $clusterDownError, - $clusterDownError, - $clusterDownError - )); - + $clusterDownError, + $clusterDownError, + $clusterDownError + )); $cluster = new RedisCluster(new Connection\Factory()); $cluster->useClusterSlots(false); @@ -1367,7 +1363,7 @@ class RedisClusterTest extends PredisTestCase /** * @medium * @group disconnected - * @group slow + * @group slow */ public function testQueryClusterNodeForSlotMapPauseDurationOnRetry() { @@ -1430,15 +1426,15 @@ class RedisClusterTest extends PredisTestCase $cluster->setRetryInterval(2000); - $startTime = time() ; + $startTime = time(); $cluster->askSlotMap(); $endTime = time(); - $totalTime=$endTime-$startTime; - $t1 = $cluster->getRetryInterval() ; + $totalTime = $endTime - $startTime; + $t1 = $cluster->getRetryInterval(); $t2 = $t1 * 2; - $expectedTime = ($t1 + $t2 )/1000 ; // expected time for 2 retries (fail 1=wait 2s, fail 2=wait 4s , OK) - $this->AssertEqualsWithDelta($expectedTime, $totalTime, 1, 'Unexpected execution time') ; + $expectedTime = ($t1 + $t2) / 1000; // expected time for 2 retries (fail 1=wait 2s, fail 2=wait 4s , OK) + $this->AssertEqualsWithDelta($expectedTime, $totalTime, 1, 'Unexpected execution time'); $this->assertCount(16384, $cluster->getSlotMap()); }