Skip to content

Commit fc6d65c

Browse files
committed
Fix CS
1 parent c9666a6 commit fc6d65c

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/DependencyInjection/SncRedisExtension.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use InvalidArgumentException;
1717
use LogicException;
18+
use Predis\Client;
1819
use RedisSentinel;
1920
use Relay\Sentinel;
2021
use Snc\RedisBundle\DependencyInjection\Configuration\Configuration;
@@ -36,6 +37,7 @@
3637
use function class_exists;
3738
use function count;
3839
use function sprintf;
40+
use function version_compare;
3941

4042
class SncRedisExtension extends Extension
4143
{
@@ -139,21 +141,21 @@ private function loadPredisClient(array $client, ContainerBuilder $container): v
139141
$client['options']['exceptions'] = $client['options']['throw_errors'];
140142
// fix ssl configuration key name
141143
$client['options']['ssl'] = $client['options']['parameters']['ssl_context'] ?? [];
142-
144+
143145
// Handle connection_persistent_id for predis conn_uid (requires predis >= 2.4.0)
144146
if (isset($client['options']['connection_persistent_id'])) {
145147
if (class_exists('Predis\Client')) {
146-
if (version_compare(\Predis\Client::VERSION, '2.4.0', '>=')) {
147-
$client['options']['conn_uid'] = $client['options']['connection_persistent_id'];
148-
} else {
148+
if (!version_compare(Client::VERSION, '2.4.0', '>=')) {
149149
throw new InvalidConfigurationException(
150150
'The connection_persistent_id parameter for Predis requires predis/predis version 2.4.0 or higher. ' .
151-
sprintf('Current version: %s', \Predis\Client::VERSION)
151+
sprintf('Current version: %s', Client::VERSION),
152152
);
153153
}
154+
155+
$client['options']['conn_uid'] = $client['options']['connection_persistent_id'];
154156
}
155157
}
156-
158+
157159
unset($client['options']['connection_async']);
158160
unset($client['options']['connection_timeout']);
159161
unset($client['options']['connection_persistent']);

src/Factory/PhpredisClientFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ private function createClientFromSentinel(string $class, array $dsns, string $al
127127
if ($options['connection_persistent']) {
128128
$connectionPersistent = $options['connection_persistent_id'] ?? $masterName;
129129
}
130-
$readTimeout = $options['read_write_timeout'] ?? 0;
131-
$parameters = $options['parameters'];
130+
131+
$readTimeout = $options['read_write_timeout'] ?? 0;
132+
$parameters = $options['parameters'];
132133

133134
foreach ($dsns as $dsn) {
134135
$args = [

tests/DependencyInjection/SncRedisExtensionTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use InvalidArgumentException;
1717
use PHPUnit\Framework\TestCase;
18+
use Predis\Client;
1819
use Redis;
1920
use RedisException;
2021
use Relay\Relay;
@@ -30,9 +31,11 @@
3031
use Symfony\Component\Yaml\Parser;
3132

3233
use function array_key_exists;
34+
use function class_exists;
3335
use function count;
3436
use function current;
3537
use function sys_get_temp_dir;
38+
use function version_compare;
3639

3740
/**
3841
* SncRedisExtensionTest
@@ -764,12 +767,12 @@ public function testPredisWithConnectionPersistentId(): void
764767
$this->markTestSkipped('Predis not available');
765768
}
766769

767-
if (version_compare(\Predis\Client::VERSION, '2.4.0', '<')) {
770+
if (version_compare(Client::VERSION, '2.4.0', '<')) {
768771
$this->markTestSkipped('Predis version 2.4.0 or higher required for connection_persistent_id');
769772
}
770773

771774
$extension = new SncRedisExtension();
772-
$config = $this->parseYaml($this->getPredisWithConnectionPersistentIdYamlConfig());
775+
$config = $this->parseYaml($this->getPredisWithConnectionPersistentIdYamlConfig());
773776
$extension->load([$config], $container = $this->getContainer());
774777

775778
$this->assertTrue($container->hasDefinition('snc_redis.default'));
@@ -783,15 +786,15 @@ public function testPredisWithConnectionPersistentIdVersionTooOld(): void
783786
$this->markTestSkipped('Predis not available');
784787
}
785788

786-
if (version_compare(\Predis\Client::VERSION, '2.4.0', '>=')) {
789+
if (version_compare(Client::VERSION, '2.4.0', '>=')) {
787790
$this->markTestSkipped('This test requires Predis version < 2.4.0');
788791
}
789792

790793
$this->expectException(InvalidConfigurationException::class);
791794
$this->expectExceptionMessage('The connection_persistent_id parameter for Predis requires predis/predis version 2.4.0 or higher');
792795

793796
$extension = new SncRedisExtension();
794-
$config = $this->parseYaml($this->getPredisWithConnectionPersistentIdYamlConfig());
797+
$config = $this->parseYaml($this->getPredisWithConnectionPersistentIdYamlConfig());
795798
$extension->load([$config], $container = $this->getContainer());
796799
}
797800

0 commit comments

Comments
 (0)