From 310bd52180f0f0525756c53b57a3d3a96b1a7afa Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Mon, 13 Jan 2025 16:35:40 -0500 Subject: [PATCH 1/4] feat: Bump PHP to 8.1+ feat: Bump LaunchDarkly to 6.4.0+ --- .github/workflows/ci.yml | 36 +++++++++--------------------------- composer.json | 4 ++-- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ddcbf0..fe7a944 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,38 +22,12 @@ jobs: strategy: matrix: include: - # 7.x configurations - - php-version: 7.3 - use-lowest-dependencies: true - shared-test-version: 4.x-dev - - php-version: 7.3 - use-lowest-dependencies: false - shared-test-version: 4.x-dev - - - php-version: 7.4 - use-lowest-dependencies: true - shared-test-version: 4.x-dev - - php-version: 7.4 - use-lowest-dependencies: false - shared-test-version: 4.x-dev - - # 8.0 configurations - - php-version: 8.0 - use-lowest-dependencies: true - shared-test-version: 4.x-dev - - php-version: 8.0 - use-lowest-dependencies: false - shared-test-version: 5.x-dev - # 8.1 configurations - php-version: 8.1 use-lowest-dependencies: true - shared-test-version: 4.x-dev - - php-version: 8.1 - use-lowest-dependencies: false shared-test-version: 5.x-dev - php-version: 8.1 - use-lowest-dependencies: false + use-lowest-dependencies: true shared-test-version: dev-main # 8.2 configurations @@ -64,6 +38,14 @@ jobs: use-lowest-dependencies: false shared-test-version: dev-main + # 8.3 configurations + - php-version: 8.3 + use-lowest-dependencies: false + shared-test-version: 5.x-dev + - php-version: 8.3 + use-lowest-dependencies: false + shared-test-version: dev-main + steps: - uses: actions/checkout@v4 with: diff --git a/composer.json b/composer.json index 77f4749..61c6cf5 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ } ], "require": { - "php": ">=7.3", - "launchdarkly/server-sdk": ">=4.0.0 <7.0.0" + "php": ">=8.1", + "launchdarkly/server-sdk": ">=6.4.0 <7.0.0" }, "require-dev": { "phpunit/phpunit": "^9" From 0996bd2a1d9fd4a5a2d80191f34d2124b2c7c633 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Mon, 13 Jan 2025 16:39:31 -0500 Subject: [PATCH 2/4] chore: Add psalm and cs-checker --- .php-cs-fixer.php | 15 +++++++++++++++ Makefile | 19 +++++++++++++++++++ composer.json | 11 +++++++++-- psalm.xml | 15 +++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .php-cs-fixer.php create mode 100644 Makefile create mode 100644 psalm.xml diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..174748f --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,15 @@ +in(__DIR__); + +$config = new PhpCsFixer\Config(); +return $config + ->setFinder($finder) + ->setUsingCache(true) + ->setRules([ + '@PSR2' => true, + 'blank_line_after_opening_tag' => true, + 'ordered_imports' => true, + 'no_unused_imports' => true, + 'array_syntax' => ['syntax' => 'short'], + ]); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a91435 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: help +help: #! Show this help message + @echo 'Usage: make [target] ... ' + @echo '' + @echo 'Targets:' + @grep -h -F '#!' $(MAKEFILE_LIST) | grep -v grep | sed 's/:.*#!/:/' | column -t -s":" + +.PHONY: test +test: #! Run unit tests + php -d xdebug.mode=coverage vendor/bin/phpunit + +.PHONY: coverage +coverage: #! Run unit tests with test coverage + php -d xdebug.mode=coverage vendor/bin/phpunit + +.PHONY: lint +lint: #! Run quality control tools (e.g. psalm) + ./vendor/bin/psalm --no-cache + composer cs-check diff --git a/composer.json b/composer.json index 61c6cf5..1111b54 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,13 @@ ], "require": { "php": ">=8.1", - "launchdarkly/server-sdk": ">=6.4.0 <7.0.0" + "launchdarkly/server-sdk": ">=6.3.0 <7.0.0" }, "require-dev": { - "phpunit/phpunit": "^9" + "friendsofphp/php-cs-fixer": "^3.68", + "phpunit/php-code-coverage": "^9", + "phpunit/phpunit": "^9", + "vimeo/psalm": "^5" }, "autoload": { "psr-4": { @@ -38,5 +41,9 @@ }, "config": { "sort-packages": true + }, + "scripts": { + "cs-check": "vendor/bin/php-cs-fixer fix --diff --dry-run --verbose --config=.php-cs-fixer.php", + "cs-fix": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php-cs-fixer.php" } } diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..4e9226b --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + From cac2b034f7e152793475d891bfba67db6af5e88d Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Mon, 13 Jan 2025 16:39:56 -0500 Subject: [PATCH 3/4] chore: Run `composer cs-fix` to improve style --- .../Impl/Integrations/PHPRedisFeatureRequester.php | 3 +-- src/LaunchDarkly/Integrations/PHPRedis.php | 3 ++- tests/PHPRedisFeatureRequesterTest.php | 2 -- tests/PHPRedisFeatureRequesterWithClientTest.php | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php index 4be9bd0..f830c4d 100644 --- a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php +++ b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php @@ -1,7 +1,6 @@ Date: Mon, 13 Jan 2025 16:57:37 -0500 Subject: [PATCH 4/4] chore: Update type hints to quiet psalm --- .github/workflows/ci.yml | 1 + .gitignore | 1 + composer.json | 1 + .../Integrations/PHPRedisFeatureRequester.php | 54 +++++++++---------- src/LaunchDarkly/Integrations/PHPRedis.php | 2 +- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe7a944..0d84ab9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: - 6379:6379 strategy: + fail-fast: false matrix: include: # 8.1 configurations diff --git a/.gitignore b/.gitignore index 35455d5..9998c07 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ docs/build docs/.phpdoc phpunit/ .phpunit.result.cache +.php-cs-fixer.cache diff --git a/composer.json b/composer.json index 1111b54..faacad4 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ ], "require": { "php": ">=8.1", + "ext-redis": "*", "launchdarkly/server-sdk": ">=6.3.0 <7.0.0" }, "require-dev": { diff --git a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php index f830c4d..fcdd0e6 100644 --- a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php +++ b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php @@ -2,32 +2,33 @@ namespace LaunchDarkly\Impl\Integrations; +use Redis; + /** * @internal */ class PHPRedisFeatureRequester extends FeatureRequesterBase { - /** @var array */ - private $_redisOptions; - /** @var \Redis */ - private $_redisInstance; - /** @var string */ - private $_prefix; + private ?array $redisOptions = null; + private ?Redis $redisInstance = null; + private ?string $prefix; - public function __construct($baseUri, $sdkKey, $options) + public function __construct(string $baseUri, string $sdkKey, array $options) { parent::__construct($baseUri, $sdkKey, $options); - $this->_prefix = $options['redis_prefix'] ?? null; - if ($this->_prefix === null || $this->_prefix === '') { - $this->_prefix = 'launchdarkly'; + /** @var ?string **/ + $this->prefix = $options['redis_prefix'] ?? null; + if ($this->prefix === null || $this->prefix === '') { + $this->prefix = 'launchdarkly'; } + /** @var ?Redis */ $client = $this->_options['phpredis_client'] ?? null; - if ($client instanceof \Redis) { - $this->_redisInstance = $client; + if ($client instanceof Redis) { + $this->redisInstance = $client; } else { - $this->_redisOptions = [ + $this->redisOptions = [ "timeout" => $options['redis_timeout'] ?? 5, "host" => $options['redis_host'] ?? 'localhost', "port" => $options['redis_port'] ?? 6379, @@ -39,37 +40,34 @@ public function __construct($baseUri, $sdkKey, $options) protected function readItemString(string $namespace, string $key): ?string { $redis = $this->getConnection(); - return $redis->hget("$this->_prefix:$namespace", $key); + return $redis->hget("$this->prefix:$namespace", $key); } protected function readItemStringList(string $namespace): ?array { $redis = $this->getConnection(); - $raw = $redis->hgetall("$this->_prefix:$namespace"); + $raw = $redis->hgetall("$this->prefix:$namespace"); return $raw ? array_values($raw) : null; } - /** - * @return \Redis - */ - protected function getConnection() + protected function getConnection(): Redis { - if ($this->_redisInstance instanceof \Redis) { - return $this->_redisInstance; + if ($this->redisInstance instanceof Redis) { + return $this->redisInstance; } - $redis = new \Redis(); + $redis = new Redis(); $redis->pconnect( - $this->_redisOptions["host"], - $this->_redisOptions["port"], - $this->_redisOptions["timeout"], + $this->redisOptions["host"], + $this->redisOptions["port"], + $this->redisOptions["timeout"], 'launchdarkly/php-server-sdk-redis-phpredis' ); - if ($this->_redisOptions['password']) { - $redis->auth($this->_redisOptions['password']); + if ($this->redisOptions['password']) { + $redis->auth($this->redisOptions['password']); } - return $this->_redisInstance = $redis; + return $this->redisInstance = $redis; } } diff --git a/src/LaunchDarkly/Integrations/PHPRedis.php b/src/LaunchDarkly/Integrations/PHPRedis.php index f02060e..547a896 100644 --- a/src/LaunchDarkly/Integrations/PHPRedis.php +++ b/src/LaunchDarkly/Integrations/PHPRedis.php @@ -39,7 +39,7 @@ public static function featureRequester($options = []) throw new \RuntimeException("phpredis extension is required to use Integrations\\PHPRedis"); } - return function ($baseUri, $sdkKey, $baseOptions) use ($options) { + return function (string $baseUri, string $sdkKey, array $baseOptions) use ($options) { return new PHPRedisFeatureRequester($baseUri, $sdkKey, array_merge($baseOptions, $options)); }; }