Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
33.33% |
1 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
EnumDisplayProvider | |
33.33% |
1 / 3 |
|
50.00% |
1 / 2 |
5.67 | |
0.00% |
0 / 1 |
supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createComponentFor | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | namespace Apie\HtmlBuilders\FieldDisplayProviders; |
3 | |
4 | use Apie\HtmlBuilders\FieldDisplayBuildContext; |
5 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
6 | use BackedEnum; |
7 | use UnitEnum; |
8 | |
9 | final class EnumDisplayProvider extends FallbackDisplayProvider |
10 | { |
11 | public function supports(mixed $object, FieldDisplayBuildContext $context): bool |
12 | { |
13 | return $object instanceof UnitEnum; |
14 | } |
15 | public function createComponentFor(mixed $object, FieldDisplayBuildContext $context): ComponentInterface |
16 | { |
17 | assert($object instanceof UnitEnum); |
18 | return parent::createComponentFor($object instanceof BackedEnum ? $object->value : $object->name, $context); |
19 | } |
20 | } |