Skip to content

Commit b2fb25a

Browse files
committed
refactor to match()
1 parent aa4d7d4 commit b2fb25a

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

src/FeatureFlags.php

Lines changed: 8 additions & 18 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,20 @@ 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-
{
74+
return match (self::getState($feature)) {
75+
FeatureState::on() => true,
76+
FeatureState::off() => false,
77+
FeatureState::dynamic() => call_user_func(function () use ($feature) {
8778
if (array_key_exists($feature, self::$dynamicHandlers)) {
88-
return self::$dynamicHandlers[$feature]($feature, request()) === true;
79+
return call_user_func(self::$dynamicHandlers[$feature], $feature, request()) === true;
8980
} elseif (is_callable(self::$defaultDynamicHandler)) {
9081
return call_user_func(self::$defaultDynamicHandler, $feature, request()) === true;
9182
}
9283

9384
return false;
94-
}
95-
}
96-
97-
return false;
85+
}),
86+
default => false
87+
};
9888
}
9989

10090
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()

0 commit comments

Comments
 (0)