1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 09:44:03 +00:00
enums/tests/Pest.php
Samuel Štancl 55478c4eb7
Metadata (#8)
* Metadata

* Fix code style (php-cs-fixer)

* Code style

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2022-03-29 20:11:06 +02:00

63 lines
1.4 KiB
PHP

<?php
use ArchTech\Enums\{InvokableCases, Options, Names, Values, From, Metadata};
use ArchTech\Enums\Meta\Meta;
use ArchTech\Enums\Meta\MetaProperty;
uses(ArchTech\Enums\Tests\TestCase::class)->in('Pest');
#[Attribute]
class Color extends MetaProperty {}
#[Attribute]
class Desc extends MetaProperty
{
public static function method(): string
{
return 'description';
}
}
#[Attribute]
class Instructions extends MetaProperty
{
public static string $method = 'help';
protected function transform(mixed $value): mixed
{
return 'Help: ' . $value;
}
}
/**
* @method string description()
* @method string color()
*/
#[Meta(Color::class, Desc::class)] // variadic syntax
enum Status: int
{
use InvokableCases, Options, Names, Values, From, Metadata;
#[Color('orange')] #[Desc('Incomplete task')]
case PENDING = 0;
#[Color('green')] #[Desc('Completed task')]
#[Instructions('Illegal meta property — not enabled on the enum')]
case DONE = 1;
}
#[Meta([Color::class, Desc::class, Instructions::class])] // array
enum Role
{
use InvokableCases, Options, Names, Values, From, Metadata;
#[Color('indigo')]
#[Desc('Administrator')]
#[Instructions('Administrators can manage the entire account')]
case ADMIN;
#[Color('gray')]
#[Desc('Read-only guest')]
#[Instructions('Guest users can only view the existing records')]
case GUEST;
}