Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
1 / 3
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EnumDisplayProvider
33.33% covered (danger)
33.33%
1 / 3
50.00% covered (danger)
50.00%
1 / 2
5.67
0.00% covered (danger)
0.00%
0 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createComponentFor
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Apie\HtmlBuilders\FieldDisplayProviders;
3
4use Apie\HtmlBuilders\FieldDisplayBuildContext;
5use Apie\HtmlBuilders\Interfaces\ComponentInterface;
6use BackedEnum;
7use UnitEnum;
8
9final 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}