Skip to content

Commit 32fdb4b

Browse files
authored
Merge pull request #2 from codinglabsau/steve/wip
Steve/wip
2 parents aa4d7d4 + 2216f8d commit 32fdb4b

File tree

6 files changed

+16
-55
lines changed

6 files changed

+16
-55
lines changed

config/feature-flags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// config for Codinglabs/FeatureFlags
2+
33
return [
44

55
/*

resources/views/.gitkeep

Whitespace-only changes.

src/Commands/FeaturesCommand.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/FeatureFlags.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
class FeatureFlags
1414
{
15-
const STATE_ON = 'on';
16-
const STATE_OFF = 'off';
17-
const STATE_DYNAMIC = 'dynamic';
18-
1915
private static ?Closure $defaultDynamicHandler = null;
2016
private static ?Closure $handleMissingFeatureClosure = null;
2117
public static array $dynamicHandlers = [];
@@ -75,26 +71,22 @@ public static function handleMissingFeatureWith(Closure $closure): void
7571

7672
public static function isEnabled(string $feature): bool
7773
{
78-
$state = self::getState($feature);
79-
80-
switch ($state) {
81-
case FeatureState::on():
82-
return true;
83-
case FeatureState::off():
84-
return false;
85-
case FeatureState::dynamic():
86-
{
87-
if (array_key_exists($feature, self::$dynamicHandlers)) {
88-
return self::$dynamicHandlers[$feature]($feature, request()) === true;
89-
} elseif (is_callable(self::$defaultDynamicHandler)) {
90-
return call_user_func(self::$defaultDynamicHandler, $feature, request()) === true;
74+
return match (self::getState($feature)) {
75+
FeatureState::on() => true,
76+
FeatureState::off() => false,
77+
FeatureState::dynamic() => call_user_func(
78+
function () use ($feature) {
79+
if (array_key_exists($feature, self::$dynamicHandlers)) {
80+
return call_user_func(self::$dynamicHandlers[$feature], $feature, request()) === true;
81+
} elseif (is_callable(self::$defaultDynamicHandler)) {
82+
return call_user_func(self::$defaultDynamicHandler, $feature, request()) === true;
83+
}
84+
85+
return false;
9186
}
92-
93-
return false;
94-
}
95-
}
96-
97-
return false;
87+
),
88+
default => false
89+
};
9890
}
9991

10092
public static function reset(): void

src/FeatureFlagsServiceProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ class FeatureFlagsServiceProvider extends PackageServiceProvider
1111
{
1212
public function configurePackage(Package $package): void
1313
{
14-
/*
15-
* This class is a Package Service Provider
16-
*
17-
* More info: https://github.com/spatie/laravel-package-tools
18-
*/
1914
$package
2015
->name('laravel-feature-flags')
2116
->hasConfigFile()

src/Traits/HasFeatureStates.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)