Skip to content

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Nov 10, 2023
1 parent 3d42b63 commit 5abd142
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
33 changes: 33 additions & 0 deletions src/SonsOfPHP/Component/FeatureToggle/Toggle/ChainToggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\FeatureToggle\Toggle;

use SonsOfPHP\Contract\FeatureToggle\ContextInterface;
use SonsOfPHP\Contract\FeatureToggle\ToggleInterface;

/**
* Chain Toggle will take multiple Toggles and if any are enabled,
* it will be enabled.
*
* @author Joshua Estes <joshua@sonsofphp.com>
*/
class ChainToggle implements ToggleInterface
{
public function __construct(
private array $toggles,
) {}

public function isEnabled(?ContextInterface $context = null): bool
{
// @todo What if I only want to return true if ALL the toggles are true?
foreach ($this->toggles as $toggle) {
if ($toggle->isEnabled($context)) {
return true;
}
}

return false;
}
}
28 changes: 28 additions & 0 deletions src/SonsOfPHP/Component/FeatureToggle/Toggle/DateRangeToggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\FeatureToggle\Toggle;

use SonsOfPHP\Contract\FeatureToggle\ContextInterface;
use SonsOfPHP\Contract\FeatureToggle\ToggleInterface;

/**
* Date range toggle will enable the toggle if it's between two dates.
*
* @author Joshua Estes <joshua@sonsofphp.com>
*/
class DateRangeToggle implements ToggleInterface
{
public function __construct(
private \DateTimeImmutable $start,
private \DateTimeImmutable $stop,
) {}

public function isEnabled(?ContextInterface $context = null): bool
{
$now = new \DateTimeImmutable();

return ($this->start >= $now && $now <= $this->stop);
}
}
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Component/FeatureToggle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace SonsOfPHP\Contract\FeatureToggle;

use SonsOfPHP\Contract\FeatureToggle\FeatureInterface;

/**
* Feature Toggle Provider Interface.
*
Expand Down

0 comments on commit 5abd142

Please sign in to comment.