Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ArrayDisplayProvider | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
20.74 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| createComponentFor | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\FieldDisplayProviders; |
| 3 | |
| 4 | use Apie\Core\Lists\ItemHashmap; |
| 5 | use Apie\HtmlBuilders\Components\Resource\FieldDisplay\SegmentDisplay; |
| 6 | use Apie\HtmlBuilders\FieldDisplayBuildContext; |
| 7 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 8 | use Apie\HtmlBuilders\Interfaces\FieldDisplayComponentProviderInterface; |
| 9 | |
| 10 | final class ArrayDisplayProvider implements FieldDisplayComponentProviderInterface |
| 11 | { |
| 12 | public function supports(mixed $object, FieldDisplayBuildContext $context): bool |
| 13 | { |
| 14 | return is_array($object) || $object instanceof ItemHashmap; |
| 15 | } |
| 16 | public function createComponentFor(mixed $object, FieldDisplayBuildContext $context): ComponentInterface |
| 17 | { |
| 18 | assert(is_array($object) || $object instanceof ItemHashmap); |
| 19 | /** @var array<string, mixed> $detailComponents */ |
| 20 | $detailComponents = []; |
| 21 | $childContext = $context->createChildContext('_'); |
| 22 | foreach ($object as $key => $value) { |
| 23 | $detailComponents[$key] = $childContext->createComponentFor($value); |
| 24 | } |
| 25 | return new SegmentDisplay($detailComponents); |
| 26 | } |
| 27 | } |