Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.00% |
24 / 25 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Form | |
96.00% |
24 / 25 |
|
50.00% |
1 / 2 |
4 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
3 | |||
| getMissingValidationErrors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Components\Forms; |
| 3 | |
| 4 | use Apie\Core\Enums\RequestMethod; |
| 5 | use Apie\HtmlBuilders\Components\BaseComponent; |
| 6 | use Apie\HtmlBuilders\FormBuildContext; |
| 7 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 8 | use Apie\HtmlBuilders\Lists\ComponentHashmap; |
| 9 | use Apie\HtmlBuilders\ValueObjects\FormName; |
| 10 | |
| 11 | class Form extends BaseComponent |
| 12 | { |
| 13 | /** |
| 14 | * @param array<string, string> $formValidationErrors |
| 15 | */ |
| 16 | public function __construct( |
| 17 | RequestMethod $method, |
| 18 | ?string $validationError, |
| 19 | array $formValidationErrors, |
| 20 | mixed $value, |
| 21 | bool $multipart, |
| 22 | ComponentInterface... $formElements |
| 23 | ) { |
| 24 | $csrfToken = null; |
| 25 | foreach ($formElements as $formElement) { |
| 26 | if ($formElement instanceof Csrf) { |
| 27 | $csrfToken = $formElement->getAttribute('token'); |
| 28 | } |
| 29 | } |
| 30 | $formGroup = new FormGroup( |
| 31 | new FormName(), |
| 32 | $validationError, |
| 33 | $formValidationErrors, |
| 34 | ...$formElements |
| 35 | ); |
| 36 | $formGroup->attributes['extraClass'] = 'unhandled-form-group'; |
| 37 | parent::__construct( |
| 38 | [ |
| 39 | 'method' => $method->value, |
| 40 | 'value' => $value, |
| 41 | 'csrf' => $csrfToken, |
| 42 | 'multipart' => $multipart, |
| 43 | 'validationError' => $validationError, |
| 44 | 'validationErrors' => $formValidationErrors, |
| 45 | ], |
| 46 | new ComponentHashmap([ |
| 47 | 'formElements' => $formGroup, |
| 48 | ]) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function getMissingValidationErrors(FormBuildContext $formBuildContext): array |
| 53 | { |
| 54 | return $this->getComponent('formElements')->getMissingValidationErrors($formBuildContext); |
| 55 | } |
| 56 | } |