Skip to content

refactor: feat/v0.6.0 branch #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: feat/v0-6-0-support
Choose a base branch
from
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "~1.10.0",
"phpstan/phpstan": "^1.11.0",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"psalm/plugin-mockery": "^1.0.0",
Expand Down Expand Up @@ -64,6 +64,7 @@
"phpstan/extension-installer": true,
"ramsey/composer-repl": true
},
"lock": false,
"sort-packages": true
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFeatureAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class OpenFeatureAPI implements API, LoggerAwareInterface

/** @var (Client & ProviderAware) | null $defaultClient */
private $defaultClient;
/** @var Array<string,Client & ProviderAware> $clientMap */
/** @var array<string,Client & ProviderAware> $clientMap */
private array $clientMap = [];

/** @var Hook[] $hooks */
Expand Down
38 changes: 9 additions & 29 deletions src/OpenFeatureClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OpenFeature;

use OpenFeature\implementation\common\Metadata;
use OpenFeature\implementation\common\ValueTypeValidator;
use OpenFeature\implementation\errors\InvalidResolutionValueError;
use OpenFeature\implementation\flags\EvaluationContext;
use OpenFeature\implementation\flags\EvaluationDetailsBuilder;
Expand Down Expand Up @@ -346,7 +345,7 @@ private function evaluateFlag(
$mergedContext,
);

if (!$resolutionDetails->getError() && !ValueTypeValidator::is($flagValueType, $resolutionDetails->getValue())) {
if (!$resolutionDetails->getError() && $flagValueType !== FlagValueType::tryFromResolutionDetails($resolutionDetails)) {
throw new InvalidResolutionValueError($flagValueType->value);
}

Expand Down Expand Up @@ -388,33 +387,14 @@ private function createProviderEvaluation(
Provider $provider,
EvaluationContextInterface $context,
): ResolutionDetails {
switch ($type->value) {
case FlagValueType::Boolean->value:
/** @var bool $defaultValue */;
$defaultValue = $defaultValue;

return $provider->resolveBooleanValue($key, $defaultValue, $context);
case FlagValueType::String->value:
/** @var string $defaultValue */;
$defaultValue = $defaultValue;

return $provider->resolveStringValue($key, $defaultValue, $context);
case FlagValueType::Integer->value:
/** @var int $defaultValue */;
$defaultValue = $defaultValue;

return $provider->resolveIntegerValue($key, $defaultValue, $context);
case FlagValueType::Float->value:
/** @var float $defaultValue */;
$defaultValue = $defaultValue;

return $provider->resolveFloatValue($key, $defaultValue, $context);
case FlagValueType::Object->value:
/** @var mixed[] $defaultValue */;
$defaultValue = $defaultValue;

return $provider->resolveObjectValue($key, $defaultValue, $context);
}
/** @psalm-suppress InvalidArgument,PossiblyInvalidArgument,PossiblyInvalidCast */
return match ($type) {
FlagValueType::Boolean => $provider->resolveBooleanValue($key, $defaultValue, $context), // @phpstan-ignore argument.type
FlagValueType::String => $provider->resolveStringValue($key, $defaultValue, $context), // @phpstan-ignore argument.type
FlagValueType::Integer => $provider->resolveIntegerValue($key, $defaultValue, $context), // @phpstan-ignore argument.type
FlagValueType::Float => $provider->resolveFloatValue($key, $defaultValue, $context), // @phpstan-ignore argument.type
FlagValueType::Object => $provider->resolveObjectValue($key, $defaultValue, $context), // @phpstan-ignore argument.type
};
}

private function determineProvider(): Provider
Expand Down
16 changes: 3 additions & 13 deletions src/implementation/common/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace OpenFeature\implementation\common;

use function array_is_list;
use function array_keys;
use function is_int;
use function sizeof;

class ArrayHelper
{
Expand All @@ -19,17 +18,8 @@ class ArrayHelper
*
* @return array<int, string>
*/
public static function getStringKeys(array $array)
public static function getStringKeys(array $array): array
{
$keys = array_keys($array);

if (sizeof($keys) === 0 || is_int($keys[0])) {
return [];
}

/** @var array<int, string> $stringKeys */
$stringKeys = $keys;

return $stringKeys;
return array_is_list($array) ? [] : array_keys($array);
}
}
18 changes: 4 additions & 14 deletions src/implementation/common/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@

namespace OpenFeature\implementation\common;

use function strlen;
use function strtolower;
use function strtoupper;
use function substr;
use function lcfirst;
use function ucfirst;

class StringHelper
{
public static function capitalize(string $input): string
{
return match (strlen($input)) {
0 => '',
1 => strtoupper($input),
default => strtoupper(substr($input, 0, 1)) . substr($input, 1),
};
return ucfirst($input);
}

public static function decapitalize(string $input): string
{
return match (strlen($input)) {
0 => '',
1 => strtolower($input),
default => strtolower(substr($input, 0, 1)) . substr($input, 1),
};
return lcfirst($input);
}
}
87 changes: 0 additions & 87 deletions src/implementation/common/ValueTypeValidator.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/implementation/events/EventMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class EventMetadata implements EventMetadataInterface
{
/**
* @param Array<string, bool|string|int|float> $eventMetadataMap
* @param array<string, bool|string|int|float> $eventMetadataMap
*/
public function __construct(protected array $eventMetadataMap = [])
{
Expand All @@ -27,7 +27,7 @@ public function has(string $key): bool
/**
* Return key-type pairs of the EventMetadata
*
* @return Array<int, string>
* @return array<int, string>
*/
public function keys(): array
{
Expand All @@ -44,7 +44,7 @@ public function get(string $key): bool | string | int | float | null
}

/**
* @return Array<string, bool|string|int|float>
* @return array<string, bool|string|int|float>
*/
public function toArray(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/events/HandlerAdderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
trait HandlerAdderTrait
{
/**
* @var Array<callable> $handlers
* @var array<callable> $handlers
*/
private array $handlers = [];
}
6 changes: 3 additions & 3 deletions src/implementation/flags/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Attributes implements AttributesInterface
{
/**
* @param Array<array-key, bool|string|int|float|DateTime|mixed[]|null> $attributesMap
* @param array<array-key, bool|string|int|float|DateTime|mixed[]|null> $attributesMap
*/
public function __construct(protected array $attributesMap = [])
{
Expand All @@ -20,7 +20,7 @@ public function __construct(protected array $attributesMap = [])
/**
* Return key-type pairs of the attributes
*
* @return Array<int, string>
* @return array<int, string>
*/
public function keys(): array
{
Expand All @@ -36,7 +36,7 @@ public function get(string $key): bool | string | int | float | DateTime | array
}

/**
* @return Array<array-key, bool|string|int|float|DateTime|mixed[]|null>
* @return array<array-key, bool|string|int|float|DateTime|mixed[]|null>
*/
public function toArray(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/implementation/flags/FlagMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FlagMetadata implements FlagMetadataInterface
{
/**
* @param Array<array-key, bool|string|int|float> $metadata
* @param array<array-key, bool|string|int|float> $metadata
*/
public function __construct(protected array $metadata = [])
{
Expand All @@ -19,7 +19,7 @@ public function __construct(protected array $metadata = [])
/**
* Return key-type pairs of the attributes
*
* @return Array<int, string>
* @return array<int, string>
*/
public function keys(): array
{
Expand All @@ -32,7 +32,7 @@ public function get(string $key): bool | string | int | float | null
}

/**
* @return Array<array-key, bool|string|int|float>
* @return array<array-key, bool|string|int|float>
*/
public function toArray(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/implementation/flags/MutableAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public static function from(AttributesInterface $attributes): MutableAttributes
$attributeMap = array_reduce(
$attributes->keys(),
/**
* @param Array<string, bool|string|int|float|DateTime|mixed[]|null> $map
* @param array<string, bool|string|int|float|DateTime|mixed[]|null> $map
*
* @return Array<string, bool|string|int|float|DateTime|mixed[]|null>
* @return array<string, bool|string|int|float|DateTime|mixed[]|null>
*/
function (array $map, string $key) use ($attributes) {
static function (array $map, string $key) use ($attributes) {
$map[$key] = $attributes->get($key);

return $map;
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/hooks/HookHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class HookHints implements HookHintsInterface
{
/**
* @param Array<string, bool | string | float | int | DateTime | mixed[] | null> $hints
* @param array<string, bool | string | float | int | DateTime | mixed[] | null> $hints
*/
public function __construct(private readonly array $hints = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/events/EventDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface EventDetails
public function getClientName(): string;

/**
* @return Array<string>
* @return array<string>
*/
public function getChangedFlags(): array;

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/events/EventMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function get(string $key): bool | string | int | float | null;
public function keys(): array;

/**
* @return Array<array-key, bool|string|int|float>
* @return array<array-key, bool|string|int|float>
*/
public function toArray(): array;
}
4 changes: 2 additions & 2 deletions src/interfaces/flags/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Attributes
/**
* Return key-type pairs of the attributes
*
* @return Array<int, string>
* @return array<int, string>
*/
public function keys(): array;

Expand All @@ -21,7 +21,7 @@ public function keys(): array;
public function get(string $key): bool | string | int | float | DateTime | array | null;

/**
* @return Array<array-key, bool|string|int|float|DateTime|mixed[]|null>
* @return array<array-key, bool|string|int|float|DateTime|mixed[]|null>
*/
public function toArray(): array;
}
Loading
Loading