Skip to content

Commit 8c0f461

Browse files
committed
chore: Cleanup and strict types
1 parent c087baa commit 8c0f461

File tree

8 files changed

+53
-21
lines changed

8 files changed

+53
-21
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: Run CI
22
on:
33
push:
4-
branches: [ main ]
4+
branches: [ main, 'feat/**' ]
55
paths-ignore:
66
- '**.md' # Do not need to run CI for markdown changes.
77
pull_request:
8-
branches: [ main ]
8+
branches: [ main, 'feat/**' ]
99
paths-ignore:
1010
- '**.md'
1111

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ help: #! Show this help message
77

88
.PHONY: test
99
test: #! Run unit tests
10-
php -d xdebug.mode=coverage vendor/bin/phpunit
10+
php vendor/bin/phpunit
1111

1212
.PHONY: coverage
1313
coverage: #! Run unit tests with test coverage

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
This library provides a Redis-backed data source for the [LaunchDarkly PHP SDK](https://github.com/launchdarkly/php-server-sdk), replacing the default behavior of querying the LaunchDarkly service endpoints. The underlying Redis client implementation is the [`phpredis`](https://github.com/phpredis/phpredis) extension. If you want to use the Predis package instead, see https://github.com/launchdarkly/php-server-sdk-redis-predis.
88

9-
The minimum version of the LaunchDarkly PHP SDK for use with this library is 4.0.0. In earlier versions of the SDK, the Redis integrations were bundled in the main SDK package.
9+
The minimum version of the LaunchDarkly PHP SDK for use with this library is 6.4.0.
1010

11-
The minimum PHP version is 7.3.
11+
The minimum PHP version is 8.1.
1212

1313
For more information, see [our SDK documentation](https://docs.launchdarkly.com/sdk/features/storing-data).
1414

@@ -27,15 +27,13 @@ php composer.phar install launchdarkly/server-sdk-redis-phpredis --save
2727
3. In your SDK configuration code, configure the Redis integration:
2828

2929
```php
30-
$fr = LaunchDarkly\Integrations\PHPRedis::featureRequester([
31-
"prefix" => "my-key-prefix"
32-
]);
33-
$config = [ "feature_requester" => $fr ];
30+
$fr = LaunchDarkly\Integrations\PHPRedis::featureRequester(
31+
$redisClient, ["prefix" => "my-key-prefix"]
32+
);
33+
$config = ["feature_requester" => $fr];
3434
$client = new LDClient("sdk_key", $config);
3535
```
3636

37-
By default, the store will try to connect to a local Redis instance on port 6379. You may specify an alternate configuration as described in the API documentation for `PHPRedis::featureRequester`. Make sure the `prefix` option corresponds to the key prefix that is being used by the Relay Proxy.
38-
3937
## About LaunchDarkly
4038

4139
* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:

phpunit.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?xml version="1.0"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" beStrictAboutResourceUsageDuringSmallTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
3-
3+
44
<logging>
55
<junit outputFile="phpunit/junit.xml"/>
66
</logging>
77

8+
<coverage>
9+
<include>
10+
<directory suffix=".php">src</directory>
11+
</include>
12+
<report>
13+
<html outputDirectory="build/phpunit/html-coverage"/>
14+
<xml outputDirectory="build/phpunit/xml-coverage"/>
15+
</report>
16+
</coverage>
17+
818
<testsuites>
919
<testsuite name="Unit Tests">
1020
<directory>tests</directory>

src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Integrations;
46

57
use LaunchDarkly\Integrations;
@@ -30,12 +32,24 @@ public function __construct(
3032

3133
protected function readItemString(string $namespace, string $key): ?string
3234
{
33-
return $this->client->hget("$this->prefix:$namespace", $key);
35+
/** @var string|false */
36+
$result = $this->client->hget("$this->prefix:$namespace", $key);
37+
if ($result === false) {
38+
return null;
39+
}
40+
41+
return $result;
3442
}
3543

3644
protected function readItemStringList(string $namespace): ?array
3745
{
46+
/** @var ?array<string, string>|false */
3847
$raw = $this->client->hgetall("$this->prefix:$namespace");
39-
return $raw ? array_values($raw) : null;
48+
49+
if ($raw === null || $raw === false) {
50+
return null;
51+
}
52+
53+
return array_values($raw);
4054
}
4155
}

src/LaunchDarkly/Integrations/PHPRedis.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Integrations;
46

57
use LaunchDarkly\Impl\Integrations;
@@ -21,9 +23,11 @@ class PHPRedis
2123
* To use this method, you must have installed the `phpredis` extension. After calling this
2224
* method, store its return value in the `feature_requester` property of your client configuration:
2325
*
24-
* $fr = LaunchDarkly\Integrations\PHPRedis::featureRequester([ "redis_prefix" => "env1" ]);
25-
* $config = [ "feature_requester" => $fr ];
26-
* $client = new LDClient("sdk_key", $config);
26+
* ```php
27+
* $fr = LaunchDarkly\Integrations\PHPRedis::featureRequester(["prefix" => "env1"]);
28+
* $config = ["feature_requester" => $fr];
29+
* $client = new LDClient("sdk_key", $config);
30+
* ```
2731
*
2832
* For more about using LaunchDarkly with databases, see the
2933
* [SDK reference guide](https://docs.launchdarkly.com/sdk/features/storing-data).
@@ -50,10 +54,12 @@ public static function featureRequester(Redis $client, $options = []): callable
5054
*
5155
* After calling this method, store its return value in the `store` property of your Big Segment configuration:
5256
*
53-
* $store = LaunchDarkly\Integrations\PHPRedis::bigSegmentsStore(["prefix" => "env1"]);
54-
* $bigSegmentsConfig = new LaunchDarkly\BigSegmentConfig(store: $store);
55-
* $config = ["big_segments" => $bigSegmentsConfig];
56-
* $client = new LDClient("sdk_key", $config);
57+
* ```php
58+
* $store = LaunchDarkly\Integrations\PHPRedis::bigSegmentsStore(["prefix" => "env1"]);
59+
* $bigSegmentsConfig = new LaunchDarkly\BigSegmentConfig(store: $store);
60+
* $config = ["big_segments" => $bigSegmentsConfig];
61+
* $client = new LDClient("sdk_key", $config);
62+
* ```
5763
*
5864
* @param array<string,mixed> $options
5965
* - `prefix`: a string to be prepended to all database keys; corresponds

tests/Impl/Integrations/PHPRedisBigSegmentsStoreTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Integrations\Tests\Impl\Integrations;
46

57
use LaunchDarkly\Impl\Integrations\PHPRedisBigSegmentsStore;

tests/Impl/Integrations/PHPRedisFeatureRequesterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Integrations\Tests\Impl\Integrations;
46

57
use LaunchDarkly\Impl\Model\FeatureFlag;

0 commit comments

Comments
 (0)