Skip to content

Commit 6d3a16b

Browse files
refactor: simplify ResourceState enums
1 parent ac92c76 commit 6d3a16b

File tree

5 files changed

+7
-57
lines changed

5 files changed

+7
-57
lines changed

config/stateful-resources.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
|
99
| Below you may register custom resource states that you want to use inside
1010
| your stateful resources. Each state must be a valid enum class that
11-
| implements the ResourceState interface and uses the AsResourceState
12-
| trait.
11+
| implements the ResourceState interface.
1312
|
1413
*/
1514
'custom_states' => [

src/Concerns/AsResourceState.php

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

src/Contracts/ResourceState.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,9 @@
22

33
namespace Farbcode\StatefulResources\Contracts;
44

5-
interface ResourceState
6-
{
7-
/**
8-
* Get the string value of the state.
9-
*/
10-
public function value(): string;
11-
12-
/**
13-
* Get the name of the state.
14-
*/
15-
public function name(): string;
16-
17-
/**
18-
* Create a state instance from a string value.
19-
*/
20-
public static function from(string $value): static;
21-
22-
/**
23-
* Try to create a state instance from a string value.
24-
*/
25-
public static function tryFrom(string $value): ?static;
26-
27-
/**
28-
* Get all available states.
29-
*/
30-
public static function cases(): array;
31-
}
5+
/**
6+
* Interface for resource state enums that must be backed by string values.
7+
*
8+
* @template T of string
9+
*/
10+
interface ResourceState extends \BackedEnum {}

src/Enums/Variant.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
namespace Farbcode\StatefulResources\Enums;
44

5-
use Farbcode\StatefulResources\Concerns\AsResourceState;
65
use Farbcode\StatefulResources\Contracts\ResourceState;
76

87
enum Variant: string implements ResourceState
98
{
10-
use AsResourceState;
11-
129
case Minimal = 'minimal';
1310
case Table = 'table';
1411
case Full = 'full';

workbench/app/Enums/CustomResourceStates.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
namespace Workbench\App\Enums;
44

5-
use Farbcode\StatefulResources\Concerns\AsResourceState;
65
use Farbcode\StatefulResources\Contracts\ResourceState;
76

87
enum CustomResourceStates: string implements ResourceState
98
{
10-
use AsResourceState;
11-
129
case Custom = 'custom';
1310
}

0 commit comments

Comments
 (0)