Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| FormGroup | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| sanitizeName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Components\Forms; |
| 3 | |
| 4 | use Apie\Core\ValueObjects\Utils; |
| 5 | use Apie\HtmlBuilders\Components\BaseComponent; |
| 6 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 7 | use Apie\HtmlBuilders\Lists\ComponentHashmap; |
| 8 | use Apie\HtmlBuilders\ValueObjects\FormName; |
| 9 | |
| 10 | class FormGroup extends BaseComponent |
| 11 | { |
| 12 | /** |
| 13 | * @param array<string, string> $validationErrors |
| 14 | */ |
| 15 | public function __construct( |
| 16 | FormName $name, |
| 17 | ?string $validationError, |
| 18 | array $validationErrors, |
| 19 | ComponentInterface... $formElements |
| 20 | ) { |
| 21 | $names = []; |
| 22 | foreach ($formElements as $formElement) { |
| 23 | $names[] = $this->sanitizeName($formElement->getAttribute('name')); |
| 24 | } |
| 25 | parent::__construct( |
| 26 | [ |
| 27 | 'groupName' => $name, |
| 28 | 'names' => $names, |
| 29 | 'keys' => array_keys($formElements), |
| 30 | 'validationError' => $validationError, |
| 31 | 'validationErrors' => $validationErrors, |
| 32 | ], |
| 33 | new ComponentHashmap($formElements) |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | private function sanitizeName(mixed $name): ?string |
| 38 | { |
| 39 | if ($name === null) { |
| 40 | return null; |
| 41 | } |
| 42 | return Utils::toString($name); |
| 43 | } |
| 44 | } |