Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ValueObjectDisplayProvider
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 createComponentFor
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\HtmlBuilders\FieldDisplayProviders;
3
4use Apie\Core\Utils\ValueObjectUtils;
5use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
6use Apie\HtmlBuilders\FieldDisplayBuildContext;
7use Apie\HtmlBuilders\Interfaces\ComponentInterface;
8use Apie\HtmlBuilders\Interfaces\FieldDisplayComponentProviderInterface;
9use ReflectionClass;
10
11final class ValueObjectDisplayProvider implements FieldDisplayComponentProviderInterface
12{
13    public function supports(mixed $object, FieldDisplayBuildContext $context): bool
14    {
15        return $object instanceof ValueObjectInterface && ValueObjectUtils::isNonCompositeValueObject(new ReflectionClass($object));
16    }
17    public function createComponentFor(mixed $object, FieldDisplayBuildContext $context): ComponentInterface
18    {
19        assert($object instanceof ValueObjectInterface);
20        return $context->createComponentFor($object->toNative());
21    }
22}