Skip to content

Commit ccb15fe

Browse files
committed
chore: Update type hints to quiet psalm
1 parent 32cfaf1 commit ccb15fe

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- 6379:6379
2121

2222
strategy:
23+
fail-fast: false
2324
matrix:
2425
include:
2526
# 8.1 configurations

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ docs/build
77
docs/.phpdoc
88
phpunit/
99
.phpunit.result.cache
10+
.php-cs-fixer.cache

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
],
2222
"require": {
2323
"php": ">=8.1",
24+
"ext-redis": "*",
2425
"launchdarkly/server-sdk": ">=6.3.0 <7.0.0"
2526
},
2627
"require-dev": {

src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22

33
namespace LaunchDarkly\Impl\Integrations;
44

5+
use Redis;
6+
57
/**
68
* @internal
79
*/
810
class PHPRedisFeatureRequester extends FeatureRequesterBase
911
{
10-
/** @var array */
11-
private $_redisOptions;
12-
/** @var \Redis */
13-
private $_redisInstance;
14-
/** @var string */
15-
private $_prefix;
12+
private ?array $redisOptions = null;
13+
private ?Redis $redisInstance = null;
14+
private ?string $prefix;
1615

17-
public function __construct($baseUri, $sdkKey, $options)
16+
public function __construct(string $baseUri, string $sdkKey, array $options)
1817
{
1918
parent::__construct($baseUri, $sdkKey, $options);
2019

21-
$this->_prefix = $options['redis_prefix'] ?? null;
22-
if ($this->_prefix === null || $this->_prefix === '') {
23-
$this->_prefix = 'launchdarkly';
20+
/** @var ?string **/
21+
$this->prefix = $options['redis_prefix'] ?? null;
22+
if ($this->prefix === null || $this->prefix === '') {
23+
$this->prefix = 'launchdarkly';
2424
}
2525

26+
/** @var ?Redis */
2627
$client = $this->_options['phpredis_client'] ?? null;
27-
if ($client instanceof \Redis) {
28-
$this->_redisInstance = $client;
28+
if ($client instanceof Redis) {
29+
$this->redisInstance = $client;
2930
} else {
30-
$this->_redisOptions = [
31+
$this->redisOptions = [
3132
"timeout" => $options['redis_timeout'] ?? 5,
3233
"host" => $options['redis_host'] ?? 'localhost',
3334
"port" => $options['redis_port'] ?? 6379,
@@ -39,37 +40,34 @@ public function __construct($baseUri, $sdkKey, $options)
3940
protected function readItemString(string $namespace, string $key): ?string
4041
{
4142
$redis = $this->getConnection();
42-
return $redis->hget("$this->_prefix:$namespace", $key);
43+
return $redis->hget("$this->prefix:$namespace", $key);
4344
}
4445

4546
protected function readItemStringList(string $namespace): ?array
4647
{
4748
$redis = $this->getConnection();
48-
$raw = $redis->hgetall("$this->_prefix:$namespace");
49+
$raw = $redis->hgetall("$this->prefix:$namespace");
4950
return $raw ? array_values($raw) : null;
5051
}
5152

52-
/**
53-
* @return \Redis
54-
*/
55-
protected function getConnection()
53+
protected function getConnection(): Redis
5654
{
57-
if ($this->_redisInstance instanceof \Redis) {
58-
return $this->_redisInstance;
55+
if ($this->redisInstance instanceof Redis) {
56+
return $this->redisInstance;
5957
}
6058

61-
$redis = new \Redis();
59+
$redis = new Redis();
6260
$redis->pconnect(
63-
$this->_redisOptions["host"],
64-
$this->_redisOptions["port"],
65-
$this->_redisOptions["timeout"],
61+
$this->redisOptions["host"],
62+
$this->redisOptions["port"],
63+
$this->redisOptions["timeout"],
6664
'launchdarkly/php-server-sdk-redis-phpredis'
6765
);
6866

69-
if ($this->_redisOptions['password']) {
70-
$redis->auth($this->_redisOptions['password']);
67+
if ($this->redisOptions['password']) {
68+
$redis->auth($this->redisOptions['password']);
7169
}
7270

73-
return $this->_redisInstance = $redis;
71+
return $this->redisInstance = $redis;
7472
}
7573
}

src/LaunchDarkly/Integrations/PHPRedis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function featureRequester($options = [])
3939
throw new \RuntimeException("phpredis extension is required to use Integrations\\PHPRedis");
4040
}
4141

42-
return function ($baseUri, $sdkKey, $baseOptions) use ($options) {
42+
return function (string $baseUri, string $sdkKey, array $baseOptions) use ($options) {
4343
return new PHPRedisFeatureRequester($baseUri, $sdkKey, array_merge($baseOptions, $options));
4444
};
4545
}

0 commit comments

Comments
 (0)