From f145901ca613451b5f6e0d851bbb79c6c1d31005 Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Thu, 9 Feb 2023 21:51:12 -0500 Subject: [PATCH] feat!: deprecate PHP 7.4 style: apply phpcbf fixes style: apply fixes for native type hinting mixed array build: remove php 7 from tool-versions build: add devenv config chore: upgrade test-harness to v0.2.2 fix: update AbstractProvider to implement Provider interface refactor: loosen interface to mixed to allow objects ci: target latest version of open-feature/sdk Signed-off-by: Tom Carrio fix: typing for internal providers Signed-off-by: Tom Carrio refactor: get all typings to a better spot Signed-off-by: Tom Carrio --- .github/workflows/pullrequest.yml | 2 +- .gitignore | 4 +- .pre-commit-config.yaml | 1 + .tool-versions | 5 +- CONTRIBUTING.md | 4 +- README.md | 6 +- composer.json | 2 +- devenv.lock | 152 ++++++++++++++++++ devenv.nix | 52 ++++++ devenv.yaml | 5 + integration/composer.json | 4 +- integration/test-harness | 2 +- phpcs.xml.dist | 4 - src/OpenFeatureClient.php | 7 +- .../common/ValueTypeValidator.php | 32 +--- src/implementation/flags/Attributes.php | 2 +- .../flags/EvaluationDetails.php | 7 +- .../flags/EvaluationDetailsBuilder.php | 2 +- .../flags/EvaluationDetailsFactory.php | 4 +- .../flags/MutableAttributes.php | 5 +- src/implementation/flags/NoOpClient.php | 25 +-- .../hooks/AbstractHookContext.php | 4 +- .../hooks/HookContextBuilder.php | 2 +- .../hooks/HookContextFactory.php | 2 +- src/implementation/hooks/HookHints.php | 4 +- .../hooks/ImmutableHookContext.php | 2 +- .../hooks/MutableHookContext.php | 5 +- .../provider/AbstractProvider.php | 10 +- src/implementation/provider/NoOpProvider.php | 10 +- .../provider/ResolutionDetails.php | 6 +- .../provider/ResolutionDetailsBuilder.php | 2 +- .../provider/ResolutionDetailsFactory.php | 2 +- src/interfaces/common/TypeValuePair.php | 2 +- src/interfaces/flags/Attributes.php | 2 +- src/interfaces/flags/EvaluationDetails.php | 2 +- src/interfaces/flags/FeatureDetails.php | 2 +- src/interfaces/flags/FeatureValues.php | 2 +- src/interfaces/flags/MutableAttributes.php | 2 +- src/interfaces/hooks/HookContext.php | 2 +- src/interfaces/hooks/HookHints.php | 6 +- src/interfaces/hooks/MutableHookContext.php | 2 +- src/interfaces/provider/Provider.php | 9 +- src/interfaces/provider/ResolutionDetails.php | 2 +- tests/TestProvider.php | 7 +- 44 files changed, 305 insertions(+), 111 deletions(-) create mode 120000 .pre-commit-config.yaml create mode 100644 devenv.lock create mode 100644 devenv.nix create mode 100644 devenv.yaml diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 31d37f9..9eecacf 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-version: ['7.4', '8.0', '8.1', '8.2'] + php-version: ['8.0', '8.1', '8.2'] steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 1fd1787..0199447 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ /build/ -/features/*.feature \ No newline at end of file +/features/*.feature + +/.devenv* \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 0000000..11b9d93 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/6v3blbcxh5aqc5k2qzf5cqyxnp8yinlp-pre-commit-config.json \ No newline at end of file diff --git a/.tool-versions b/.tool-versions index 60d1396..4b245b8 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,3 @@ -# php 7.4.30 -# php 8.0.24 +php 8.0.24 # php 8.1.11 -php 8.2.1 \ No newline at end of file +# php 8.2.1 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fff9c09..91dccbe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,11 +4,11 @@ ### System Requirements -PHP 8+ is recommended. PHP 7.4 is EOL and support will be removed in an upcoming release. +PHP 8+ is required. ### Compilation target(s) -We target compatibility with PHP versions 7.4, 8.0, 8.1, and 8.2. +We target compatibility with PHP versions 8.0, 8.1, and 8.2. ### Installation and Dependencies diff --git a/README.md b/README.md index 1628ba2..57dbcd4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Specification](https://img.shields.io/static/v1?label=Specification&message=v0.5.1&color=yellow)](https://github.com/open-feature/spec/tree/v0.5.1) [![Latest Stable Version](http://poser.pugx.org/open-feature/sdk/v)](https://packagist.org/packages/open-feature/sdk) [![Total Downloads](http://poser.pugx.org/open-feature/sdk/downloads)](https://packagist.org/packages/open-feature/sdk) -![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg) +![PHP 8.0+](https://img.shields.io/badge/php->=8.0-blue.svg) [![License](http://poser.pugx.org/open-feature/sdk/license)](https://packagist.org/packages/open-feature/sdk) [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/6853/badge)](https://bestpractices.coreinfrastructure.org/projects/6853) @@ -106,9 +106,7 @@ The OpenFeature project maintains the [open-feature/php-sdk-contrib](https://git ### PHP Versioning -This library targets PHP version 7.4 and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK. - -⚠️ **PHP version 7.4 is EOL and support will shortly be dropped from this package.** +This library targets PHP version 8.0 and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK. This package also has a `.tool-versions` file for use with PHP version managers like `asdf`. diff --git a/composer.json b/composer.json index 6829a2d..cd901ca 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.4 || ^8", + "php": "^8", "myclabs/php-enum": "^1.8", "psr/log": "^1.1" }, diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..a79b9f0 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,152 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1675875772, + "narHash": "sha256-sYXHPZ4tsjdG+UXK0mYnABhiS/RuzHiV9uGOU9YakwE=", + "owner": "cachix", + "repo": "devenv", + "rev": "eac5eb12eb42765f5f252972dc876d1f96b03dfe", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1675758091, + "narHash": "sha256-7gFSQbSVAFUHtGCNHPF7mPc5CcqDk9M2+inlVPZSneg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "747927516efcb5e31ba03b7ff32f61f6d47e7d87", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1673800717, + "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1671271357, + "narHash": "sha256-xRJdLbWK4v2SewmSStYrcLa0YGJpleufl44A19XSW8k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "40f79f003b6377bd2f4ed4027dde1f8f922995dd", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1675688762, + "narHash": "sha256-oit/SxMk0B380ASuztBGQLe8TttO1GJiXF8aZY9AYEc=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ab608394886fb04b8a5df3cb0bab2598400e3634", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..077cf85 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,52 @@ +{ pkgs, ... }: + +{ + + # https://devenv.sh/packages/ + packages = [ pkgs.git ]; + + # https://devenv.sh/languages/ + languages.nix.enable = true; + languages.php.enable = true; + languages.php.package = pkgs.php80; + + # https://devenv.sh/basics/ + env.PROJECT_NAME = "openfeature-php-sdk"; + + # https://devenv.sh/scripts/ + scripts.hello.exec = "echo $ Started devenv shell in $PROJECT_NAME"; + + enterShell = '' + hello + echo + git --version + php --version + echo + + # optimization step -- files and directories that match entries + # in the .gitignore will still be traversed, and the .devenv + # directory contains over 5000 files and 121MB. + if ! grep -E "excludesfile.+\.gitignore" .git/config &>/dev/null + then + git config --local core.excludesfile .gitignore + fi + ''; + + ## https://devenv.sh/pre-commit-hooks/ + pre-commit.hooks = { + # # general formatting + # prettier.enable = true; + # github actions + actionlint.enable = true; + # nix + deadnix.enable = true; + nixfmt.enable = true; + # php + phpcbf.enable = true; + # # ensure Markdown code is executable + # mdsh.enable = true; + }; + + # https://devenv.sh/processes/ + # processes.ping.exec = "ping example.com"; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..292df95 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,5 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable + pre-commit-hooks: + url: github:cachix/pre-commit-hooks.nix \ No newline at end of file diff --git a/integration/composer.json b/integration/composer.json index d48fb23..5759e28 100644 --- a/integration/composer.json +++ b/integration/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.4 || ^8", + "php": "^8", "open-feature/sdk": "^1.1.1", "open-feature/flagd-provider": "^0.3.0", "guzzlehttp/guzzle": "^7.5", @@ -31,7 +31,7 @@ "url": "../", "options": { "versions": { - "open-feature/sdk": "1.1.1" + "open-feature/sdk": "1.4.0" } } } diff --git a/integration/test-harness b/integration/test-harness index 5153eac..64c09ed 160000 --- a/integration/test-harness +++ b/integration/test-harness @@ -1 +1 @@ -Subproject commit 5153eac71dc47413da4326bdb49a94e573b99578 +Subproject commit 64c09ed8f87b06f1a844d55deab50a071ed2dea8 diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 14aa9f2..55d9d3a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,10 +20,6 @@ - - - - diff --git a/src/OpenFeatureClient.php b/src/OpenFeatureClient.php index cd140a9..8a4432b 100644 --- a/src/OpenFeatureClient.php +++ b/src/OpenFeatureClient.php @@ -292,7 +292,7 @@ public function getObjectDetails(string $flagKey, $defaultValue, ?EvaluationCont private function evaluateFlag( string $flagValueType, string $flagKey, - $defaultValue, + bool | string | int | float | DateTime | array | null $defaultValue, ?EvaluationContextInterface $invocationContext = null, ?EvaluationOptionsInterface $options = null ): EvaluationDetailsInterface { @@ -388,13 +388,10 @@ private function evaluateFlag( return $details; } - /** - * @param mixed $defaultValue - */ private function createProviderEvaluation( string $type, string $key, - $defaultValue, + mixed $defaultValue, Provider $provider, EvaluationContextInterface $context ): ResolutionDetails { diff --git a/src/implementation/common/ValueTypeValidator.php b/src/implementation/common/ValueTypeValidator.php index 16f0b36..955f468 100644 --- a/src/implementation/common/ValueTypeValidator.php +++ b/src/implementation/common/ValueTypeValidator.php @@ -17,80 +17,64 @@ class ValueTypeValidator { /** * Validates whether the value is a boolean type - * - * @param mixed $value */ - public static function isBoolean($value): bool + public static function isBoolean(mixed $value): bool { return is_bool($value); } /** * Validates whether the value is a string type - * - * @param mixed $value */ - public static function isString($value): bool + public static function isString(mixed $value): bool { return is_string($value); } /** * Validates whether the value is an integer type - * - * @param mixed $value */ - public static function isInteger($value): bool + public static function isInteger(mixed $value): bool { return is_int($value); } /** * Validates whether the value is a float type - * - * @param mixed $value */ - public static function isFloat($value): bool + public static function isFloat(mixed $value): bool { return is_float($value); } /** * Validates whether the value is a structure - * - * @param mixed $value */ - public static function isStructure($value): bool + public static function isStructure(mixed $value): bool { return self::isArray($value); } /** * Validates whether the value is an Array type - * - * @param mixed $value */ - public static function isArray($value): bool + public static function isArray(mixed $value): bool { return is_array($value); } /** * Validates whether the value is a DateTime type - * - * @param mixed $value */ - public static function isDateTime($value): bool + public static function isDateTime(mixed $value): bool { return $value instanceof DateTime; } /** * Validates whether the value is valid for the given type - * - * @param mixed $value */ - public static function is(string $type, $value): bool + public static function is(string $type, mixed $value): bool { switch ($type) { case FlagValueType::BOOLEAN: diff --git a/src/implementation/flags/Attributes.php b/src/implementation/flags/Attributes.php index 671a7c8..9676c4e 100644 --- a/src/implementation/flags/Attributes.php +++ b/src/implementation/flags/Attributes.php @@ -36,7 +36,7 @@ public function keys(): array /** * @return bool|string|int|float|DateTime|mixed[]|null */ - public function get(string $key) + public function get(string $key): bool | string | int | float | DateTime | array | null { if (isset($this->attributesMap[$key])) { return $this->attributesMap[$key]; diff --git a/src/implementation/flags/EvaluationDetails.php b/src/implementation/flags/EvaluationDetails.php index c6db1f5..d96c46b 100644 --- a/src/implementation/flags/EvaluationDetails.php +++ b/src/implementation/flags/EvaluationDetails.php @@ -11,8 +11,9 @@ class EvaluationDetails implements EvaluationDetailsInterface { private string $flagKey = ''; + /** @var bool|string|int|float|DateTime|mixed[]|null $value */ - private $value; + private bool | string | int | float | DateTime | array | null $value = null; private ?ResolutionError $error = null; private ?string $reason = null; private ?string $variant = null; @@ -40,7 +41,7 @@ public function setFlagKey(string $flagKey): void * * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getValue() + public function getValue(): bool | string | int | float | DateTime | array | null { return $this->value; } @@ -48,7 +49,7 @@ public function getValue() /** * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public function setValue($value): void + public function setValue(bool | string | int | float | DateTime | array | null $value): void { $this->value = $value; } diff --git a/src/implementation/flags/EvaluationDetailsBuilder.php b/src/implementation/flags/EvaluationDetailsBuilder.php index 3ed8d8b..7cb4dc6 100644 --- a/src/implementation/flags/EvaluationDetailsBuilder.php +++ b/src/implementation/flags/EvaluationDetailsBuilder.php @@ -27,7 +27,7 @@ public function withFlagKey(string $flagKey): EvaluationDetailsBuilder /** * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public function withValue($value): EvaluationDetailsBuilder + public function withValue(bool | string | int | float | DateTime | array | null $value): EvaluationDetailsBuilder { $this->details->setValue($value); diff --git a/src/implementation/flags/EvaluationDetailsFactory.php b/src/implementation/flags/EvaluationDetailsFactory.php index fc5ee53..6115799 100644 --- a/src/implementation/flags/EvaluationDetailsFactory.php +++ b/src/implementation/flags/EvaluationDetailsFactory.php @@ -11,11 +11,11 @@ class EvaluationDetailsFactory { /** - * Provides a simple method for building EvaluationDetails from a given value + * Provides a simple method for building EvaluationDetails from a given value\ * * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public static function from(string $flagKey, $value): EvaluationDetails + public static function from(string $flagKey, bool | string | int | float | DateTime | array | null $value): EvaluationDetails { return (new EvaluationDetailsBuilder()) ->withFlagKey($flagKey) diff --git a/src/implementation/flags/MutableAttributes.php b/src/implementation/flags/MutableAttributes.php index 138e7b7..662ce7c 100644 --- a/src/implementation/flags/MutableAttributes.php +++ b/src/implementation/flags/MutableAttributes.php @@ -32,10 +32,7 @@ function (array $map, string $key) use ($attributes) { return new MutableAttributes($attributeMap); } - /** - * @param bool|string|int|float|DateTime|mixed[]|null $value - */ - public function add(string $key, $value): void + public function add(string $key, bool | string | int | float | DateTime | array | null $value): void { $this->attributesMap[$key] = $value; } diff --git a/src/implementation/flags/NoOpClient.php b/src/implementation/flags/NoOpClient.php index bbc32cf..e5135ca 100644 --- a/src/implementation/flags/NoOpClient.php +++ b/src/implementation/flags/NoOpClient.php @@ -60,15 +60,16 @@ public function getFloatDetails(string $flagKey, float $defaultValue, ?Evaluatio * * @return mixed[] */ - public function getObjectValue(string $flagKey, $defaultValue, ?EvaluationContextInterface $context = null, ?EvaluationOptions $options = null): array - { + public function getObjectValue( + string $flagKey, + array $defaultValue, + ?EvaluationContextInterface $context = null, + ?EvaluationOptions $options = null + ): array { return $defaultValue; } - /** - * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue - */ - public function getObjectDetails(string $flagKey, $defaultValue, ?EvaluationContextInterface $context = null, ?EvaluationOptions $options = null): EvaluationDetails + public function getObjectDetails(string $flagKey, bool | string | int | float | DateTime | array | null $defaultValue, ?EvaluationContextInterface $context = null, ?EvaluationOptions $options = null): EvaluationDetails { return EvaluationDetailsFactory::from($flagKey, $defaultValue); } @@ -88,17 +89,17 @@ public function setEvaluationContext(EvaluationContextInterface $context): void // no-op } - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function getHooks(): array { return []; } - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function setHooks(array $hooks): void { // no-op diff --git a/src/implementation/hooks/AbstractHookContext.php b/src/implementation/hooks/AbstractHookContext.php index 7c98064..39fbeba 100644 --- a/src/implementation/hooks/AbstractHookContext.php +++ b/src/implementation/hooks/AbstractHookContext.php @@ -18,7 +18,7 @@ abstract class AbstractHookContext protected string $flagKey = ''; protected string $type = ''; /** @var bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - protected $defaultValue = null; + protected bool | string | int | float | DateTime | array | null $defaultValue = null; protected EvaluationContextInterface $evaluationContext; protected MetadataInterface $clientMetadata; protected MetadataInterface $providerMetadata; @@ -26,7 +26,7 @@ abstract class AbstractHookContext /** * @param HookContext|mixed[]|null $hookContext */ - public function __construct($hookContext = null) + public function __construct(HookContext | array | null $hookContext = null) { /** * utility constructor to build a HookContext from an existing diff --git a/src/implementation/hooks/HookContextBuilder.php b/src/implementation/hooks/HookContextBuilder.php index 521a05f..5e94f37 100644 --- a/src/implementation/hooks/HookContextBuilder.php +++ b/src/implementation/hooks/HookContextBuilder.php @@ -36,7 +36,7 @@ public function withType(string $type): self /** * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - public function withDefaultValue($defaultValue): self + public function withDefaultValue(bool | string | int | float | DateTime | array | null $defaultValue): self { $this->hookContext->setDefaultValue($defaultValue); diff --git a/src/implementation/hooks/HookContextFactory.php b/src/implementation/hooks/HookContextFactory.php index 71ae635..1317dfc 100644 --- a/src/implementation/hooks/HookContextFactory.php +++ b/src/implementation/hooks/HookContextFactory.php @@ -18,7 +18,7 @@ class HookContextFactory public static function from( string $flagKey, string $type, - $defaultValue, + bool | string | int | float | DateTime | array | null $defaultValue, ?EvaluationContextInterface $evaluationContext, Metadata $clientMetadata, Metadata $providerMetadata diff --git a/src/implementation/hooks/HookHints.php b/src/implementation/hooks/HookHints.php index 271e5a6..2385d57 100644 --- a/src/implementation/hooks/HookHints.php +++ b/src/implementation/hooks/HookHints.php @@ -16,9 +16,9 @@ class HookHints implements HookHintsInterface private array $hints = []; /** - * @return bool | string | float | int | DateTime | mixed[] | null + * @return bool|string|int|float|DateTime|mixed[]|null */ - public function get(string $key) + public function get(string $key): bool | string | int | float | DateTime | array | null { if (key_exists($key, $this->hints)) { return $this->hints[$key]; diff --git a/src/implementation/hooks/ImmutableHookContext.php b/src/implementation/hooks/ImmutableHookContext.php index fac9aaf..e0ed360 100644 --- a/src/implementation/hooks/ImmutableHookContext.php +++ b/src/implementation/hooks/ImmutableHookContext.php @@ -24,7 +24,7 @@ public function getType(): string /** * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getDefaultValue() + public function getDefaultValue(): bool | string | int | float | DateTime | array | null { return $this->defaultValue; } diff --git a/src/implementation/hooks/MutableHookContext.php b/src/implementation/hooks/MutableHookContext.php index 766e43f..a8a1b77 100644 --- a/src/implementation/hooks/MutableHookContext.php +++ b/src/implementation/hooks/MutableHookContext.php @@ -22,10 +22,7 @@ public function setType(string $type): void $this->type = $type; } - /** - * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue - */ - public function setDefaultValue($defaultValue): void + public function setDefaultValue(bool | string | int | float | DateTime | array | null $defaultValue): void { $this->defaultValue = $defaultValue; } diff --git a/src/implementation/provider/AbstractProvider.php b/src/implementation/provider/AbstractProvider.php index 8304e0c..885f306 100644 --- a/src/implementation/provider/AbstractProvider.php +++ b/src/implementation/provider/AbstractProvider.php @@ -4,6 +4,7 @@ namespace OpenFeature\implementation\provider; +use DateTime; use OpenFeature\implementation\common\Metadata; use OpenFeature\interfaces\common\Metadata as MetadataInterface; use OpenFeature\interfaces\flags\EvaluationContext; @@ -34,10 +35,11 @@ abstract public function resolveIntegerValue(string $flagKey, int $defaultValue, abstract public function resolveFloatValue(string $flagKey, float $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface; - /** - * @inheritdoc - */ - abstract public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface; + abstract public function resolveObjectValue( + string $flagKey, + bool | string | int | float | DateTime | array | null $defaultValue, + ?EvaluationContext $context = null + ): ResolutionDetailsInterface; /** * @return Hook[] diff --git a/src/implementation/provider/NoOpProvider.php b/src/implementation/provider/NoOpProvider.php index 890bf45..bf2e65a 100644 --- a/src/implementation/provider/NoOpProvider.php +++ b/src/implementation/provider/NoOpProvider.php @@ -4,6 +4,7 @@ namespace OpenFeature\implementation\provider; +use DateTime; use OpenFeature\interfaces\flags\EvaluationContext; use OpenFeature\interfaces\provider\Provider; use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface; @@ -33,10 +34,13 @@ public function resolveFloatValue(string $flagKey, float $defaultValue, ?Evaluat } /** - * @inheritdoc + * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface - { + public function resolveObjectValue( + string $flagKey, + bool | string | int | float | DateTime | array | null $defaultValue, + ?EvaluationContext $context = null + ): ResolutionDetailsInterface { return ResolutionDetailsFactory::fromSuccess($defaultValue); } } diff --git a/src/implementation/provider/ResolutionDetails.php b/src/implementation/provider/ResolutionDetails.php index de5648c..29750d9 100644 --- a/src/implementation/provider/ResolutionDetails.php +++ b/src/implementation/provider/ResolutionDetails.php @@ -11,7 +11,7 @@ class ResolutionDetails implements ResolutionDetailsInterface { /** @var bool|string|int|float|DateTime|mixed[]|null $value */ - private $value = null; + private bool | string | int | float | DateTime | array | null $value = null; private ?ResolutionError $error = null; private ?string $reason = null; private ?string $variant = null; @@ -19,7 +19,7 @@ class ResolutionDetails implements ResolutionDetailsInterface /** * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getValue() + public function getValue(): bool | string | int | float | DateTime | array | null { return $this->value; } @@ -27,7 +27,7 @@ public function getValue() /** * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public function setValue($value): void + public function setValue(bool | string | int | float | DateTime | array | null $value): void { $this->value = $value; } diff --git a/src/implementation/provider/ResolutionDetailsBuilder.php b/src/implementation/provider/ResolutionDetailsBuilder.php index f4b784c..73ae2c7 100644 --- a/src/implementation/provider/ResolutionDetailsBuilder.php +++ b/src/implementation/provider/ResolutionDetailsBuilder.php @@ -20,7 +20,7 @@ public function __construct() /** * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public function withValue($value): ResolutionDetailsBuilder + public function withValue(bool | string | int | float | DateTime | array | null $value): ResolutionDetailsBuilder { $this->details->setValue($value); diff --git a/src/implementation/provider/ResolutionDetailsFactory.php b/src/implementation/provider/ResolutionDetailsFactory.php index 2542d9a..79d2e1b 100644 --- a/src/implementation/provider/ResolutionDetailsFactory.php +++ b/src/implementation/provider/ResolutionDetailsFactory.php @@ -12,7 +12,7 @@ class ResolutionDetailsFactory /** * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public static function fromSuccess($value): ResolutionDetailsInterface + public static function fromSuccess(bool | string | int | float | DateTime | array | null $value): ResolutionDetailsInterface { return (new ResolutionDetailsBuilder()) ->withValue($value) diff --git a/src/interfaces/common/TypeValuePair.php b/src/interfaces/common/TypeValuePair.php index 88f2733..767ac57 100644 --- a/src/interfaces/common/TypeValuePair.php +++ b/src/interfaces/common/TypeValuePair.php @@ -13,5 +13,5 @@ public function getType(): string; /** * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getValue(); + public function getValue(): bool | string | int | float | DateTime | array | null; } diff --git a/src/interfaces/flags/Attributes.php b/src/interfaces/flags/Attributes.php index c1e0dac..1adb975 100644 --- a/src/interfaces/flags/Attributes.php +++ b/src/interfaces/flags/Attributes.php @@ -18,7 +18,7 @@ public function keys(): array; /** * @return bool|string|int|float|DateTime|mixed[]|null */ - public function get(string $key); + public function get(string $key): bool | string | int | float | DateTime | array | null; /** * @return Array diff --git a/src/interfaces/flags/EvaluationDetails.php b/src/interfaces/flags/EvaluationDetails.php index a2fdf63..26f931f 100644 --- a/src/interfaces/flags/EvaluationDetails.php +++ b/src/interfaces/flags/EvaluationDetails.php @@ -33,7 +33,7 @@ public function getFlagKey(): string; * * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getValue(); + public function getValue(): bool | string | int | float | DateTime | array | null; /** * ----------------- diff --git a/src/interfaces/flags/FeatureDetails.php b/src/interfaces/flags/FeatureDetails.php index 1a2ea73..6d9336d 100644 --- a/src/interfaces/flags/FeatureDetails.php +++ b/src/interfaces/flags/FeatureDetails.php @@ -26,5 +26,5 @@ public function getFloatDetails(string $flagKey, float $defaultValue, ?Evaluatio /** * @param mixed[] $defaultValue */ - public function getObjectDetails(string $flagKey, $defaultValue, ?EvaluationContext $context = null, ?EvaluationOptions $options = null): EvaluationDetails; + public function getObjectDetails(string $flagKey, array $defaultValue, ?EvaluationContext $context = null, ?EvaluationOptions $options = null): EvaluationDetails; } diff --git a/src/interfaces/flags/FeatureValues.php b/src/interfaces/flags/FeatureValues.php index 4e33853..165f2dd 100644 --- a/src/interfaces/flags/FeatureValues.php +++ b/src/interfaces/flags/FeatureValues.php @@ -29,5 +29,5 @@ public function getFloatValue(string $flagKey, float $defaultValue, ?EvaluationC * * @return mixed[] */ - public function getObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null, ?EvaluationOptions $options = null); + public function getObjectValue(string $flagKey, array $defaultValue, ?EvaluationContext $context = null, ?EvaluationOptions $options = null); } diff --git a/src/interfaces/flags/MutableAttributes.php b/src/interfaces/flags/MutableAttributes.php index 6a3edf7..45094d0 100644 --- a/src/interfaces/flags/MutableAttributes.php +++ b/src/interfaces/flags/MutableAttributes.php @@ -13,5 +13,5 @@ interface MutableAttributes extends Attributes * * @param bool|string|int|float|DateTime|mixed[]|null $value */ - public function add(string $key, $value): void; + public function add(string $key, bool | string | int | float | DateTime | array | null $value): void; } diff --git a/src/interfaces/hooks/HookContext.php b/src/interfaces/hooks/HookContext.php index 3af93c3..6ae0599 100644 --- a/src/interfaces/hooks/HookContext.php +++ b/src/interfaces/hooks/HookContext.php @@ -52,7 +52,7 @@ public function getType(): string; * * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getDefaultValue(); + public function getDefaultValue(): bool | string | int | float | DateTime | array | null; /** * ----------------- diff --git a/src/interfaces/hooks/HookHints.php b/src/interfaces/hooks/HookHints.php index d9c2b68..c291191 100644 --- a/src/interfaces/hooks/HookHints.php +++ b/src/interfaces/hooks/HookHints.php @@ -13,11 +13,13 @@ * ----------------- * hook hints MUST be a structure supports definition of arbitrary properties, with keys * of type string, and values of type boolean | string | number | datetime | structure + * + * @return bool|string|int|float|DateTime|mixed[]|null */ interface HookHints extends StringIndexed { /** - * @return bool | string | float | int | DateTime | mixed[] | null + * @return bool|string|int|float|DateTime|mixed[]|null */ - public function get(string $key); + public function get(string $key): bool | string | float | int | DateTime | array | null; } diff --git a/src/interfaces/hooks/MutableHookContext.php b/src/interfaces/hooks/MutableHookContext.php index 559f972..b6c144f 100644 --- a/src/interfaces/hooks/MutableHookContext.php +++ b/src/interfaces/hooks/MutableHookContext.php @@ -17,7 +17,7 @@ public function setType(string $type): void; /** * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - public function setDefaultValue($defaultValue): void; + public function setDefaultValue(bool | string | int | float | DateTime | array | null $defaultValue): void; public function setEvaluationContext(EvaluationContext $evaluationContext): void; diff --git a/src/interfaces/provider/Provider.php b/src/interfaces/provider/Provider.php index 5052a79..e3f8d41 100644 --- a/src/interfaces/provider/Provider.php +++ b/src/interfaces/provider/Provider.php @@ -4,6 +4,7 @@ namespace OpenFeature\interfaces\provider; +use DateTime; use OpenFeature\interfaces\common\MetadataGetter; use OpenFeature\interfaces\flags\EvaluationContext; use OpenFeature\interfaces\hooks\HooksGetter; @@ -47,7 +48,11 @@ public function resolveFloatValue(string $flagKey, float $defaultValue, ?Evaluat /** * Resolves the flag value for the provided flag key as an object * - * @param mixed[] $defaultValue + * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetails; + public function resolveObjectValue( + string $flagKey, + bool | string | int | float | DateTime | array | null $defaultValue, + ?EvaluationContext $context = null + ): ResolutionDetails; } diff --git a/src/interfaces/provider/ResolutionDetails.php b/src/interfaces/provider/ResolutionDetails.php index ac54158..c8ddbc1 100644 --- a/src/interfaces/provider/ResolutionDetails.php +++ b/src/interfaces/provider/ResolutionDetails.php @@ -23,7 +23,7 @@ interface ResolutionDetails * * @return bool|string|int|float|DateTime|mixed[]|null */ - public function getValue(); + public function getValue(): bool | string | int | float | DateTime | array | null; /** * --------------- diff --git a/tests/TestProvider.php b/tests/TestProvider.php index 1eb09c8..56a6b26 100644 --- a/tests/TestProvider.php +++ b/tests/TestProvider.php @@ -4,6 +4,7 @@ namespace OpenFeature\Test; +use DateTime; use OpenFeature\implementation\common\Metadata; use OpenFeature\implementation\provider\ResolutionDetailsFactory; use OpenFeature\interfaces\common\Metadata as MetadataInterface; @@ -58,11 +59,9 @@ public function resolveFloatValue(string $flagKey, float $defaultValue, ?Evaluat } /** - * Resolves the flag value for the provided flag key as an object - * - * @param mixed[] $defaultValue + * @param bool|string|int|float|DateTime|mixed[]|null $defaultValue */ - public function resolveObjectValue(string $flagKey, $defaultValue, ?EvaluationContext $context = null): ResolutionDetails + public function resolveObjectValue(string $flagKey, bool | string | int | float | DateTime | array | null $defaultValue, ?EvaluationContext $context = null): ResolutionDetails { return ResolutionDetailsFactory::fromSuccess($defaultValue); }