Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
14.29% covered (danger)
14.29%
1 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ArrayDisplayProvider
14.29% covered (danger)
14.29%
1 / 7
50.00% covered (danger)
50.00%
1 / 2
20.74
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
2
 createComponentFor
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace Apie\HtmlBuilders\FieldDisplayProviders;
3
4use Apie\Core\Lists\ItemHashmap;
5use Apie\HtmlBuilders\Components\Resource\FieldDisplay\SegmentDisplay;
6use Apie\HtmlBuilders\FieldDisplayBuildContext;
7use Apie\HtmlBuilders\Interfaces\ComponentInterface;
8use Apie\HtmlBuilders\Interfaces\FieldDisplayComponentProviderInterface;
9
10final 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}