Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| HiddenIdComponentProvider | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| createComponentFor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Factories\Concrete; |
| 3 | |
| 4 | use Apie\Core\Enums\ScalarType; |
| 5 | use Apie\Core\Metadata\MetadataFactory; |
| 6 | use Apie\Core\Metadata\NullableMetadataInterface; |
| 7 | use Apie\HtmlBuilders\Components\Dashboard\RawContents; |
| 8 | use Apie\HtmlBuilders\FormBuildContext; |
| 9 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 10 | use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface; |
| 11 | use ReflectionType; |
| 12 | |
| 13 | class 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 | } |