Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
9.09% |
1 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NullComponentProvider | |
9.09% |
1 / 11 |
|
50.00% |
1 / 2 |
9.76 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| createComponentFor | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Factories\Concrete; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsSingleInput; |
| 5 | use Apie\HtmlBuilders\Components\Forms\SingleInput; |
| 6 | use Apie\HtmlBuilders\FormBuildContext; |
| 7 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 8 | use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface; |
| 9 | use ReflectionNamedType; |
| 10 | use ReflectionType; |
| 11 | |
| 12 | /** |
| 13 | * Creates a form field for null. |
| 14 | */ |
| 15 | class NullComponentProvider implements FormComponentProviderInterface |
| 16 | { |
| 17 | public function supports(ReflectionType $type, FormBuildContext $context): bool |
| 18 | { |
| 19 | return $type instanceof ReflectionNamedType && $type->getName() === 'null'; |
| 20 | } |
| 21 | |
| 22 | public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface |
| 23 | { |
| 24 | return new SingleInput( |
| 25 | $context->getFormName(), |
| 26 | $context->getFilledInValue(), |
| 27 | $context->createTranslationLabel(), |
| 28 | $type->allowsNull(), |
| 29 | $type, |
| 30 | new CmsSingleInput( |
| 31 | ['null'] |
| 32 | ) |
| 33 | ); |
| 34 | } |
| 35 | } |