Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Activator/ArrayActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function __construct(array $features = [])
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'array';
}

/**
* {@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);
Expand Down
6 changes: 3 additions & 3 deletions src/Activator/CacheActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ public function __construct(FeatureActivatorInterface $activator, CachePool $cac
*
* @return FeatureActivatorInterface
*/
public function getActivator()
public function getActivator(): FeatureActivatorInterface
{
return $this->activator;
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->activator->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());

Expand Down
8 changes: 4 additions & 4 deletions src/Activator/ChainActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -68,23 +68,23 @@ public function add(FeatureActivatorInterface $activator)
*
* @return FeatureActivatorInterface[]
*/
public function getActivators()
public function getActivators(): array
{
return $this->bag;
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'chain';
}

/**
* {@inheritdoc}
*/
public function isActive($name, Context $context)
public function isActive(string $name, ?Context $context): bool
{
$strategy = $context->get(self::CONTEXT_STRATEGY_NAME, $this->strategy);

Expand Down
4 changes: 2 additions & 2 deletions src/Activator/ConstraintActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function __construct(ConstraintResolverInterface $resolver, array $featur
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'constraint';
}

/**
* {@inheritdoc}
*/
public function isActive($name, Context $context)
public function isActive(string $name, ?Context $context): bool
{
if (!array_key_exists($name, $this->features)) {
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/Activator/CookieActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -103,15 +103,15 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'cookie';
}

/**
* {@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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Activator/EnvironmentActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,15 +41,15 @@ public function __construct(array $variables = [], $forceRequest = false)
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'environment';
}

/**
* {@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;
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions src/Activator/FeatureActivatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Manager/FeatureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Manager/FeatureManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ interface FeatureManagerInterface
*
* @return bool
*/
public function isActive($name, Context $context = null);
public function isActive(string $name, ?Context $context = null): bool;
}
11 changes: 6 additions & 5 deletions src/Model/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Context implements Serializable
* Context constructor
*
* @param array<string, mixed> $storage
* @throws AlreadyDefinedException
*/
public function __construct(array $storage = [])
{
Expand All @@ -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));
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -81,7 +82,7 @@ public function get($name, $default = null)
*
* @return array<string, mixed>
*/
public function all()
public function all(): array
{
return $this->storage;
}
Expand All @@ -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);
}
Expand Down
Loading