Skip to content

Commit 4155441

Browse files
committed
chore: Cleanup and strict types
1 parent fdeae98 commit 4155441

File tree

12 files changed

+163
-296
lines changed

12 files changed

+163
-296
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 [Predis](https://github.com/predis/predis) package. If you want to use the `phpredis` extension instead, see https://github.com/launchdarkly/php-server-sdk-redis-phpredis.
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 @@ If your project does not already have a dependency on Predis (`predis/predis`),
2727
2. In your SDK configuration code, configure the Redis integration:
2828

2929
```php
30-
$fr = LaunchDarkly\Integrations\Redis::featureRequester([
31-
"prefix" => "my-key-prefix"
32-
]);
33-
$config = [ "feature_requester" => $fr ];
30+
$fr = LaunchDarkly\Integrations\Redis::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 `Redis::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/RedisBigSegmentsStore.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public function __construct(
3131
private readonly LoggerInterface $logger,
3232
readonly array $options = []
3333
) {
34-
$this->prefix = $options['prefix'] ?? Integrations\Redis::DEFAULT_PREFIX;
34+
$prefix = $options['prefix'] ?? null;
35+
if (empty($prefix)) {
36+
$prefix = Integrations\Redis::DEFAULT_PREFIX;
37+
}
38+
$this->prefix = $prefix;
3539
}
3640

3741
public function getMetadata(): Types\BigSegmentsStoreMetadata

src/LaunchDarkly/Impl/Integrations/RedisFeatureRequester.php

Lines changed: 7 additions & 1 deletion
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;
@@ -20,7 +22,11 @@ public function __construct(
2022
array $options
2123
) {
2224
parent::__construct($baseUri, $sdkKey, $options);
23-
$this->prefix = $options['prefix'] ?? Integrations\Redis::DEFAULT_PREFIX;
25+
$prefix = $options['prefix'] ?? null;
26+
if (empty($prefix)) {
27+
$prefix = Integrations\Redis::DEFAULT_PREFIX;
28+
}
29+
$this->prefix = $prefix;
2430
}
2531

2632
protected function readItemString(string $namespace, string $key): ?string

src/LaunchDarkly/Integrations/Redis.php

Lines changed: 15 additions & 15 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\RedisBigSegmentsStore;
@@ -20,9 +22,11 @@ class Redis
2022
*
2123
* After calling this method, store its return value in the `feature_requester` property of your client configuration:
2224
*
23-
* $fr = LaunchDarkly\Integrations\Redis::featureRequester(["prefix" => "env1"]);
24-
* $config = ["feature_requester" => $fr];
25-
* $client = new LDClient("sdk_key", $config);
25+
* ```php
26+
* $fr = LaunchDarkly\Integrations\Redis::featureRequester(["prefix" => "env1"]);
27+
* $config = ["feature_requester" => $fr];
28+
* $client = new LDClient("sdk_key", $config);
29+
* ```
2630
*
2731
* For more about using LaunchDarkly with databases, see the
2832
* [SDK reference guide](https://docs.launchdarkly.com/sdk/features/storing-data).
@@ -44,23 +48,19 @@ public static function featureRequester(ClientInterface $client, array $options
4448
*
4549
* After calling this method, store its return value in the `store` property of your Big Segment configuration:
4650
*
47-
* $store = LaunchDarkly\Integrations\Redis::bigSegmentsStore(["prefix" => "env1"]);
48-
* $bigSegmentsConfig = new LaunchDarkly\BigSegmentConfig(store: $store);
49-
* $config = ["big_segments" => $bigSegmentsConfig];
50-
* $client = new LDClient("sdk_key", $config);
51-
*
52-
* For more about using LaunchDarkly with databases, see the
53-
* [SDK reference guide](https://docs.launchdarkly.com/sdk/features/storing-data).
51+
* ```php
52+
* $store = LaunchDarkly\Integrations\Redis::bigSegmentsStore(["prefix" => "env1"]);
53+
* $bigSegmentsConfig = new LaunchDarkly\BigSegmentConfig(store: $store);
54+
* $config = ["big_segments" => $bigSegmentsConfig];
55+
* $client = new LDClient("sdk_key", $config);
56+
* ```
5457
*
5558
* @param array<string,mixed> $options
5659
* - `prefix`: a string to be prepended to all database keys; corresponds
5760
* to the prefix setting in ld-relay
58-
* @return callable(LoggerInterface, array): Subsystems\BigSegmentsStore
5961
*/
60-
public static function bigSegmentsStore(ClientInterface $client, array $options = []): callable
62+
public static function bigSegmentsStore(ClientInterface $client, LoggerInterface $logger, array $options = []): Subsystems\BigSegmentsStore
6163
{
62-
return function (LoggerInterface $logger, array $baseOptions) use ($client, $options): Subsystems\BigSegmentsStore {
63-
return new RedisBigSegmentsStore($client, $logger, array_merge($baseOptions, $options));
64-
};
64+
return new RedisBigSegmentsStore($client, $logger, $options);
6565
}
6666
}

tests/Impl/Integrations/RedisBigSegmentsStoreTest.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 Exception;

0 commit comments

Comments
 (0)