diff --git a/src/Activator/ArrayActivator.php b/src/Activator/ArrayActivator.php index 3acac24..45297df 100644 --- a/src/Activator/ArrayActivator.php +++ b/src/Activator/ArrayActivator.php @@ -32,7 +32,7 @@ public function __construct(array $features = []) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'array'; } @@ -40,7 +40,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { if (array_key_exists($name, $this->features)) { return filter_var($this->features[$name], FILTER_VALIDATE_BOOLEAN); diff --git a/src/Activator/CacheActivator.php b/src/Activator/CacheActivator.php index a6e9bcc..d2cbfba 100644 --- a/src/Activator/CacheActivator.php +++ b/src/Activator/CacheActivator.php @@ -67,7 +67,7 @@ public function __construct(FeatureActivatorInterface $activator, CachePool $cac * * @return FeatureActivatorInterface */ - public function getActivator() + public function getActivator(): FeatureActivatorInterface { return $this->activator; } @@ -75,7 +75,7 @@ public function getActivator() /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return $this->activator->getName(); } @@ -83,7 +83,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { $hash = static::CACHE_KEY . '#' . $this->getName() . '#' . md5($name . '-' . $context->serialize()); diff --git a/src/Activator/ChainActivator.php b/src/Activator/ChainActivator.php index db391a9..11efcc7 100644 --- a/src/Activator/ChainActivator.php +++ b/src/Activator/ChainActivator.php @@ -46,7 +46,7 @@ class ChainActivator implements FeatureActivatorInterface * * @param int $strategy */ - public function __construct($strategy = self::STRATEGY_FIRST_MATCH) + public function __construct(int $strategy = self::STRATEGY_FIRST_MATCH) { $this->strategy = $strategy; } @@ -68,7 +68,7 @@ public function add(FeatureActivatorInterface $activator) * * @return FeatureActivatorInterface[] */ - public function getActivators() + public function getActivators(): array { return $this->bag; } @@ -76,7 +76,7 @@ public function getActivators() /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'chain'; } @@ -84,7 +84,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { $strategy = $context->get(self::CONTEXT_STRATEGY_NAME, $this->strategy); diff --git a/src/Activator/ConstraintActivator.php b/src/Activator/ConstraintActivator.php index 866c4b8..210806f 100644 --- a/src/Activator/ConstraintActivator.php +++ b/src/Activator/ConstraintActivator.php @@ -42,7 +42,7 @@ public function __construct(ConstraintResolverInterface $resolver, array $featur /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'constraint'; } @@ -50,7 +50,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { if (!array_key_exists($name, $this->features)) { return false; diff --git a/src/Activator/CookieActivator.php b/src/Activator/CookieActivator.php index f7f250e..a491321 100644 --- a/src/Activator/CookieActivator.php +++ b/src/Activator/CookieActivator.php @@ -71,10 +71,10 @@ class CookieActivator implements FeatureActivatorInterface */ public function __construct( array $features, - $name = 'flagception', - $separator = ',', - $mode = self::WHITELIST, - callable $extractor = null + string $name = 'flagception', + string $separator = ',', + string $mode = self::WHITELIST, + ?callable $extractor = null ) { if (!in_array($mode, [self::BLACKLIST, self::WHITELIST], true)) { throw new InvalidArgumentException( @@ -103,7 +103,7 @@ public function __construct( /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'cookie'; } @@ -111,7 +111,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { // Disable features which aren't whitelisted if ($this->mode === self::WHITELIST && !in_array($name, $this->features, true)) { diff --git a/src/Activator/EnvironmentActivator.php b/src/Activator/EnvironmentActivator.php index 8667fcd..b8f67b7 100644 --- a/src/Activator/EnvironmentActivator.php +++ b/src/Activator/EnvironmentActivator.php @@ -32,7 +32,7 @@ class EnvironmentActivator implements FeatureActivatorInterface * @param array $variables * @param bool $forceRequest */ - public function __construct(array $variables = [], $forceRequest = false) + public function __construct(array $variables = [], bool $forceRequest = false) { $this->variables = $variables; $this->forceRequest = $forceRequest; @@ -41,7 +41,7 @@ public function __construct(array $variables = [], $forceRequest = false) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'environment'; } @@ -49,7 +49,7 @@ public function getName() /** * {@inheritdoc} */ - public function isActive($name, Context $context) + public function isActive(string $name, ?Context $context): bool { if ($this->forceRequest === false && !array_key_exists($name, $this->variables)) { return false; @@ -69,7 +69,7 @@ public function isActive($name, Context $context) * * @return string|null */ - private function getEnv($name) + private function getEnv($name): ?string { return filter_var( array_key_exists($name, $_ENV) ? $_ENV[$name] : getenv($name), diff --git a/src/Activator/FeatureActivatorInterface.php b/src/Activator/FeatureActivatorInterface.php index 2d54715..bff8228 100644 --- a/src/Activator/FeatureActivatorInterface.php +++ b/src/Activator/FeatureActivatorInterface.php @@ -17,16 +17,16 @@ interface FeatureActivatorInterface * * @return string */ - public function getName(); + public function getName(): string; /** * Check if the given feature name is active * Optional the context object can contain further options to check * * @param string $name - * @param Context $context + * @param Context|null $context * * @return bool */ - public function isActive($name, Context $context); + public function isActive(string $name, ?Context $context): bool; } diff --git a/src/Manager/FeatureManager.php b/src/Manager/FeatureManager.php index 60d90d3..bf5355c 100644 --- a/src/Manager/FeatureManager.php +++ b/src/Manager/FeatureManager.php @@ -34,7 +34,7 @@ class FeatureManager implements FeatureManagerInterface * @param FeatureActivatorInterface $activator * @param ContextDecoratorInterface|null $decorator */ - public function __construct(FeatureActivatorInterface $activator, ContextDecoratorInterface $decorator = null) + public function __construct(FeatureActivatorInterface $activator, ?ContextDecoratorInterface $decorator = null) { $this->activator = $activator; $this->decorator = $decorator; @@ -43,7 +43,7 @@ public function __construct(FeatureActivatorInterface $activator, ContextDecorat /** * {@inheritdoc} */ - public function isActive($name, Context $context = null) + public function isActive(string $name, ?Context $context = null): bool { if ($context === null) { $context = new Context(); diff --git a/src/Manager/FeatureManagerInterface.php b/src/Manager/FeatureManagerInterface.php index b7d9985..0ed673d 100644 --- a/src/Manager/FeatureManagerInterface.php +++ b/src/Manager/FeatureManagerInterface.php @@ -20,5 +20,5 @@ interface FeatureManagerInterface * * @return bool */ - public function isActive($name, Context $context = null); + public function isActive(string $name, ?Context $context = null): bool; } diff --git a/src/Model/Context.php b/src/Model/Context.php index 2fd1b3b..906125c 100644 --- a/src/Model/Context.php +++ b/src/Model/Context.php @@ -24,6 +24,7 @@ class Context implements Serializable * Context constructor * * @param array $storage + * @throws AlreadyDefinedException */ public function __construct(array $storage = []) { @@ -41,7 +42,7 @@ public function __construct(array $storage = []) * @return void * @throws AlreadyDefinedException */ - public function add($name, $value) + public function add(string $name, $value) { if (array_key_exists($name, $this->storage)) { throw new AlreadyDefinedException(sprintf('Context value with key `%s` already defined', $name)); @@ -58,7 +59,7 @@ public function add($name, $value) * * @return void */ - public function replace($name, $value) + public function replace(string $name, $value) { $this->storage[$name] = $value; } @@ -71,7 +72,7 @@ public function replace($name, $value) * * @return mixed */ - public function get($name, $default = null) + public function get(string $name, $default = null) { return array_key_exists($name, $this->storage) ? $this->storage[$name] : $default; } @@ -81,7 +82,7 @@ public function get($name, $default = null) * * @return array */ - public function all() + public function all(): array { return $this->storage; } @@ -93,7 +94,7 @@ public function all() * * @return bool */ - public function has($name) + public function has(string $name): bool { return array_key_exists($name, $this->storage); }