diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ddcbf0..0d84ab9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,40 +20,15 @@ jobs: - 6379:6379 strategy: + fail-fast: false 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 +39,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/.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/.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 77f4749..faacad4 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,15 @@ } ], "require": { - "php": ">=7.3", - "launchdarkly/server-sdk": ">=4.0.0 <7.0.0" + "php": ">=8.1", + "ext-redis": "*", + "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 +42,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 @@ + + + + + + + + + diff --git a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php index 4be9bd0..fcdd0e6 100644 --- a/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php +++ b/src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php @@ -1,34 +1,34 @@ _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, @@ -40,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 919051d..547a896 100644 --- a/src/LaunchDarkly/Integrations/PHPRedis.php +++ b/src/LaunchDarkly/Integrations/PHPRedis.php @@ -1,4 +1,5 @@