Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
PolymorphicForm | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
20 / 20 |
|
100.00% |
1 / 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\Lists\ComponentHashmap; |
7 | use ReflectionClass; |
8 | |
9 | class PolymorphicForm extends BaseComponent |
10 | { |
11 | /** |
12 | * @param ReflectionClass<object> $class |
13 | * @param array<string, string> $formValidationErrors |
14 | */ |
15 | public function __construct( |
16 | RequestMethod $method, |
17 | ReflectionClass $class, |
18 | ?string $validationError, |
19 | array $formValidationErrors, |
20 | mixed $value, |
21 | bool $multipart, |
22 | Csrf $csrf, |
23 | ComponentHashmap $discriminatorMap |
24 | ) { |
25 | $csrfToken = $csrf->getAttribute('token'); |
26 | $subtypes = []; |
27 | $mapping = [ |
28 | '_csrf' => $csrf, |
29 | ]; |
30 | foreach ($discriminatorMap as $name => $component) { |
31 | $mapping[$name] = $this->makePrototype(md5($class->name . $method->name . $name), $component); |
32 | $subtypes[] = $name; |
33 | } |
34 | parent::__construct( |
35 | [ |
36 | 'method' => $method->value, |
37 | 'value' => $value, |
38 | 'csrf' => $csrfToken, |
39 | 'multipart' => $multipart, |
40 | 'subtypes' => $subtypes, |
41 | 'validationError' => $validationError, |
42 | 'validationErrors' => $formValidationErrors, |
43 | ], |
44 | new ComponentHashmap($mapping) |
45 | ); |
46 | } |
47 | } |