Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HiddenIdComponentProvider
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 createComponentFor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\HtmlBuilders\Factories\Concrete;
3
4use Apie\Core\Enums\ScalarType;
5use Apie\Core\Metadata\MetadataFactory;
6use Apie\Core\Metadata\NullableMetadataInterface;
7use Apie\HtmlBuilders\Components\Dashboard\RawContents;
8use Apie\HtmlBuilders\FormBuildContext;
9use Apie\HtmlBuilders\Interfaces\ComponentInterface;
10use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface;
11use ReflectionType;
12
13class HiddenIdComponentProvider implements FormComponentProviderInterface
14{
15    public function supports(ReflectionType $type, FormBuildContext $context): bool
16    {
17        if (!$type->allowsNull() || $context->getFormName()->getChildFormFieldName() !== 'id') {
18            return false;
19        }
20        $metadata = MetadataFactory::getCreationMetadata($type, $context->getApieContext());
21        $scalar = $metadata instanceof NullableMetadataInterface ? $metadata->toScalarType(true) : $metadata->toScalarType();
22        return $scalar === ScalarType::STRING || $scalar === ScalarType::INTEGER;
23    }
24
25    public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface
26    {
27        return new RawContents('<!-- id is filled in automatically -->');
28    }
29}