Skip to content

Commit fb44796

Browse files
committed
fix: updates to support 8.1 and errors
1 parent a8a160b commit fb44796

21 files changed

+54
-110
lines changed

src/OpenFeatureClient.php

+12-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature;
66

7-
use DateTime;
87
use OpenFeature\implementation\common\Metadata;
98
use OpenFeature\implementation\common\ValueTypeValidator;
109
use OpenFeature\implementation\errors\InvalidResolutionValueError;
@@ -16,7 +15,6 @@
1615
use OpenFeature\implementation\hooks\HookContextFactory;
1716
use OpenFeature\implementation\hooks\HookExecutor;
1817
use OpenFeature\implementation\hooks\HookHints;
19-
use OpenFeature\implementation\provider\Reason;
2018
use OpenFeature\implementation\provider\ResolutionError;
2119
use OpenFeature\interfaces\common\LoggerAwareTrait;
2220
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
@@ -30,6 +28,7 @@
3028
use OpenFeature\interfaces\hooks\HooksAwareTrait;
3129
use OpenFeature\interfaces\provider\ErrorCode;
3230
use OpenFeature\interfaces\provider\Provider;
31+
use OpenFeature\interfaces\provider\Reason;
3332
use OpenFeature\interfaces\provider\ResolutionDetails;
3433
use OpenFeature\interfaces\provider\ThrowableWithResolutionError;
3534
use Psr\Log\LoggerAwareInterface;
@@ -282,12 +281,12 @@ public function getObjectDetails(string $flagKey, $defaultValue, ?EvaluationCont
282281
* -----------------
283282
* Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the default value in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.
284283
*
285-
* @param bool|string|int|float|DateTime|mixed[]|null $defaultValue
284+
* @param bool|string|int|float|mixed[]|null $defaultValue
286285
*/
287286
private function evaluateFlag(
288287
FlagValueType $flagValueType,
289288
string $flagKey,
290-
bool | string | int | float | DateTime | array | null $defaultValue,
289+
bool | string | int | float | array | null $defaultValue,
291290
?EvaluationContextInterface $invocationContext = null,
292291
?EvaluationOptionsInterface $options = null,
293292
): EvaluationDetailsInterface {
@@ -383,6 +382,9 @@ private function evaluateFlag(
383382
return $details;
384383
}
385384

385+
/**
386+
* @param bool|string|int|float|mixed[]|null $defaultValue
387+
*/
386388
private function createProviderEvaluation(
387389
FlagValueType $type,
388390
string $key,
@@ -394,35 +396,28 @@ private function createProviderEvaluation(
394396
case FlagValueType::Boolean->value:
395397
/** @var bool $defaultValue */;
396398
$defaultValue = $defaultValue;
397-
$resolver = $provider->resolveBooleanValue(...);
398399

399-
break;
400+
return $provider->resolveBooleanValue($key, $defaultValue, $context);
400401
case FlagValueType::String->value:
401402
/** @var string $defaultValue */;
402403
$defaultValue = $defaultValue;
403-
$resolver = $provider->resolveStringValue(...);
404404

405-
break;
405+
return $provider->resolveStringValue($key, $defaultValue, $context);
406406
case FlagValueType::Integer->value:
407407
/** @var int $defaultValue */;
408408
$defaultValue = $defaultValue;
409-
$resolver = $provider->resolveIntegerValue(...);
410409

411-
break;
410+
return $provider->resolveIntegerValue($key, $defaultValue, $context);
412411
case FlagValueType::Float->value:
413412
/** @var float $defaultValue */;
414413
$defaultValue = $defaultValue;
415-
$resolver = $provider->resolveFloatValue(...);
416414

417-
break;
415+
return $provider->resolveFloatValue($key, $defaultValue, $context);
418416
case FlagValueType::Object->value:
419-
/** @var object $defaultValue */;
417+
/** @var mixed[] $defaultValue */;
420418
$defaultValue = $defaultValue;
421-
$resolver = $provider->resolveObjectValue(...);
422419

423-
break;
420+
return $provider->resolveObjectValue($key, $defaultValue, $context);
424421
}
425-
426-
return $resolver($key, $defaultValue, $context);
427422
}
428423
}

src/implementation/common/ValueTypeValidator.php

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public static function is(FlagValueType $type, mixed $value): bool
8282
FlagValueType::Integer => self::isInteger($value),
8383
FlagValueType::String => self::isString($value),
8484
FlagValueType::Object => self::isStructure($value) || self::isArray($value),
85-
default => false,
8685
};
8786
}
8887
}

src/implementation/flags/EvaluationDetails.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
namespace OpenFeature\implementation\flags;
66

7-
use DateTime;
87
use OpenFeature\interfaces\flags\EvaluationDetails as EvaluationDetailsInterface;
98
use OpenFeature\interfaces\provider\ResolutionError;
109

1110
class EvaluationDetails implements EvaluationDetailsInterface
1211
{
1312
private string $flagKey = '';
1413

15-
/** @var bool|string|int|float|DateTime|mixed[]|null $value */
16-
private bool | string | int | float | DateTime | array | null $value = null;
14+
/** @var bool|string|int|float|mixed[]|null $value */
15+
private bool | string | int | float | array | null $value = null;
1716
private ?ResolutionError $error = null;
1817
private ?string $reason = null;
1918
private ?string $variant = null;
@@ -38,17 +37,17 @@ public function setFlagKey(string $flagKey): void
3837
* -----------------
3938
* The evaluation details structure's value field MUST contain the evaluated flag value.
4039
*
41-
* @return bool|string|int|float|DateTime|mixed[]|null
40+
* @return bool|string|int|float|mixed[]|null
4241
*/
43-
public function getValue(): bool | string | int | float | DateTime | array | null
42+
public function getValue(): bool | string | int | float | array | null
4443
{
4544
return $this->value;
4645
}
4746

4847
/**
49-
* @param bool|string|int|float|DateTime|mixed[]|null $value
48+
* @param bool|string|int|float|mixed[]|null $value
5049
*/
51-
public function setValue(bool | string | int | float | DateTime | array | null $value): void
50+
public function setValue(bool | string | int | float | array | null $value): void
5251
{
5352
$this->value = $value;
5453
}

src/implementation/flags/EvaluationDetailsBuilder.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\flags;
66

7-
use DateTime;
87
use OpenFeature\interfaces\flags\EvaluationDetails as EvaluationDetailsInterface;
98
use OpenFeature\interfaces\provider\ResolutionError;
109

@@ -25,9 +24,9 @@ public function withFlagKey(string $flagKey): EvaluationDetailsBuilder
2524
}
2625

2726
/**
28-
* @param bool|string|int|float|DateTime|mixed[]|null $value
27+
* @param bool|string|int|float|mixed[]|null $value
2928
*/
30-
public function withValue(bool | string | int | float | DateTime | array | null $value): EvaluationDetailsBuilder
29+
public function withValue(bool | string | int | float | array | null $value): EvaluationDetailsBuilder
3130
{
3231
$this->details->setValue($value);
3332

src/implementation/flags/EvaluationDetailsFactory.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\flags;
66

7-
use DateTime;
87
use OpenFeature\interfaces\flags\EvaluationDetails;
98
use OpenFeature\interfaces\provider\ResolutionDetails;
109

@@ -13,9 +12,9 @@ class EvaluationDetailsFactory
1312
/**
1413
* Provides a simple method for building EvaluationDetails from a given value\
1514
*
16-
* @param bool|string|int|float|DateTime|mixed[]|null $value
15+
* @param bool|string|int|float|mixed[]|null $value
1716
*/
18-
public static function from(string $flagKey, bool | string | int | float | DateTime | array | null $value): EvaluationDetails
17+
public static function from(string $flagKey, bool | string | int | float | array | null $value): EvaluationDetails
1918
{
2019
return (new EvaluationDetailsBuilder())
2120
->withFlagKey($flagKey)

src/implementation/flags/NoOpClient.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\flags;
66

7-
use DateTime;
87
use OpenFeature\implementation\common\Metadata;
98
use OpenFeature\interfaces\flags\Client;
109
use OpenFeature\interfaces\flags\EvaluationContext as EvaluationContextInterface;
@@ -69,7 +68,7 @@ public function getObjectValue(
6968
return $defaultValue;
7069
}
7170

72-
public function getObjectDetails(string $flagKey, bool | string | int | float | DateTime | array | null $defaultValue, ?EvaluationContextInterface $context = null, ?EvaluationOptions $options = null): EvaluationDetails
71+
public function getObjectDetails(string $flagKey, bool | string | int | float | array | null $defaultValue, ?EvaluationContextInterface $context = null, ?EvaluationOptions $options = null): EvaluationDetails
7372
{
7473
return EvaluationDetailsFactory::from($flagKey, $defaultValue);
7574
}

src/implementation/hooks/AbstractHookContext.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\hooks;
66

7-
use DateTime;
87
use Exception;
98
use OpenFeature\implementation\common\Metadata;
109
use OpenFeature\implementation\flags\EvaluationContext;
@@ -13,15 +12,14 @@
1312
use OpenFeature\interfaces\flags\FlagValueType;
1413
use OpenFeature\interfaces\hooks\HookContext;
1514

16-
use function array_values;
1715
use function is_array;
1816

1917
abstract class AbstractHookContext
2018
{
21-
protected string $flagKey;
22-
protected FlagValueType $type;
23-
/** @var bool|string|int|float|DateTime|mixed[]|null $defaultValue */
24-
protected bool | string | int | float | DateTime | array | null $defaultValue = null;
19+
protected string $flagKey = '';
20+
protected FlagValueType $type = FlagValueType::Boolean;
21+
/** @var bool|string|int|float|mixed[]|null $defaultValue */
22+
protected bool | string | int | float | array | null $defaultValue = null;
2523
protected EvaluationContextInterface $evaluationContext;
2624
protected MetadataInterface $clientMetadata;
2725
protected MetadataInterface $providerMetadata;
@@ -48,7 +46,7 @@ public function __construct(HookContext | array | null $hookContext = null)
4846
$this->clientMetadata = $hookContext->getClientMetadata();
4947
$this->providerMetadata = $hookContext->getProviderMetadata();
5048
} elseif (is_array($hookContext)) {
51-
foreach (array_values(self::REQUIRED_PROPERTIES) as $requiredProperty) {
49+
foreach (self::REQUIRED_PROPERTIES as $requiredProperty) {
5250
if (!isset($hookContext[$requiredProperty])) {
5351
throw new Exception('Required property missing from hook context');
5452
}

src/implementation/hooks/HookContextBuilder.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\hooks;
66

7-
use DateTime;
87
use OpenFeature\interfaces\common\Metadata;
98
use OpenFeature\interfaces\flags\EvaluationContext;
109
use OpenFeature\interfaces\flags\FlagValueType;
@@ -35,9 +34,9 @@ public function withType(FlagValueType $type): self
3534
}
3635

3736
/**
38-
* @param bool|string|int|float|DateTime|mixed[]|null $defaultValue
37+
* @param bool|string|int|float|mixed[]|null $defaultValue
3938
*/
40-
public function withDefaultValue(bool | string | int | float | DateTime | array | null $defaultValue): self
39+
public function withDefaultValue(bool | string | int | float | array | null $defaultValue): self
4140
{
4241
$this->hookContext->setDefaultValue($defaultValue);
4342

src/implementation/hooks/HookContextFactory.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\hooks;
66

7-
use DateTime;
87
use OpenFeature\implementation\flags\EvaluationContext;
98
use OpenFeature\interfaces\common\Metadata;
109
use OpenFeature\interfaces\flags\EvaluationContext as EvaluationContextInterface;
@@ -14,12 +13,12 @@
1413
class HookContextFactory
1514
{
1615
/**
17-
* @param bool|string|int|float|DateTime|mixed[]|null $defaultValue
16+
* @param bool|string|int|float|mixed[]|null $defaultValue
1817
*/
1918
public static function from(
2019
string $flagKey,
2120
FlagValueType $type,
22-
bool | string | int | float | DateTime | array | null $defaultValue,
21+
bool | string | int | float | array | null $defaultValue,
2322
?EvaluationContextInterface $evaluationContext,
2423
Metadata $clientMetadata,
2524
Metadata $providerMetadata,

src/implementation/hooks/ImmutableHookContext.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\hooks;
66

7-
use DateTime;
87
use OpenFeature\interfaces\common\Metadata;
98
use OpenFeature\interfaces\flags\EvaluationContext;
109
use OpenFeature\interfaces\flags\FlagValueType;
@@ -23,9 +22,9 @@ public function getType(): FlagValueType
2322
}
2423

2524
/**
26-
* @return bool|string|int|float|DateTime|mixed[]|null
25+
* @return bool|string|int|float|mixed[]|null
2726
*/
28-
public function getDefaultValue(): bool | string | int | float | DateTime | array | null
27+
public function getDefaultValue(): bool | string | int | float | array | null
2928
{
3029
return $this->defaultValue;
3130
}

src/implementation/hooks/MutableHookContext.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\hooks;
66

7-
use DateTime;
87
use OpenFeature\interfaces\common\Metadata;
98
use OpenFeature\interfaces\flags\EvaluationContext;
109
use OpenFeature\interfaces\flags\FlagValueType;
@@ -23,7 +22,7 @@ public function setType(FlagValueType $type): void
2322
$this->type = $type;
2423
}
2524

26-
public function setDefaultValue(bool | string | int | float | DateTime | array | null $defaultValue): void
25+
public function setDefaultValue(bool | string | int | float | array | null $defaultValue): void
2726
{
2827
$this->defaultValue = $defaultValue;
2928
}

src/implementation/provider/Reason.php

-15
This file was deleted.

src/implementation/provider/ResolutionDetails.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44

55
namespace OpenFeature\implementation\provider;
66

7-
use DateTime;
87
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
98
use OpenFeature\interfaces\provider\ResolutionError;
109

1110
class ResolutionDetails implements ResolutionDetailsInterface
1211
{
13-
/** @var bool|string|int|float|DateTime|mixed[]|null $value */
14-
private bool | string | int | float | DateTime | array | null $value = null;
12+
/** @var bool|string|int|float|mixed[]|null $value */
13+
private bool | string | int | float | array | null $value = null;
1514
private ?ResolutionError $error = null;
1615
private ?string $reason = null;
1716
private ?string $variant = null;
1817

1918
/**
20-
* @return bool|string|int|float|DateTime|mixed[]|null
19+
* @return bool|string|int|float|mixed[]|null
2120
*/
22-
public function getValue(): bool | string | int | float | DateTime | array | null
21+
public function getValue(): bool | string | int | float | array | null
2322
{
2423
return $this->value;
2524
}
2625

2726
/**
28-
* @param bool|string|int|float|DateTime|mixed[]|null $value
27+
* @param bool|string|int|float|mixed[]|null $value
2928
*/
30-
public function setValue(bool | string | int | float | DateTime | array | null $value): void
29+
public function setValue(bool | string | int | float | array | null $value): void
3130
{
3231
$this->value = $value;
3332
}

src/implementation/provider/ResolutionDetailsBuilder.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenFeature\implementation\provider;
66

7-
use DateTime;
87
use OpenFeature\interfaces\provider\ResolutionDetails as ResolutionDetailsInterface;
98
use OpenFeature\interfaces\provider\ResolutionError;
109

@@ -18,9 +17,9 @@ public function __construct()
1817
}
1918

2019
/**
21-
* @param bool|string|int|float|DateTime|mixed[]|null $value
20+
* @param bool|string|int|float|mixed[]|null $value
2221
*/
23-
public function withValue(bool | string | int | float | DateTime | array | null $value): ResolutionDetailsBuilder
22+
public function withValue(bool | string | int | float | array | null $value): ResolutionDetailsBuilder
2423
{
2524
$this->details->setValue($value);
2625

0 commit comments

Comments
 (0)