Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
79.17% |
19 / 24 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FormSplit | |
79.17% |
19 / 24 |
|
50.00% |
1 / 2 |
4.14 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
2 | |||
| withName | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Components\Forms; |
| 3 | |
| 4 | use Apie\HtmlBuilders\Components\BaseComponent; |
| 5 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 6 | use Apie\HtmlBuilders\Lists\ComponentHashmap; |
| 7 | use Apie\HtmlBuilders\ValueObjects\FormName; |
| 8 | |
| 9 | class FormSplit extends BaseComponent |
| 10 | { |
| 11 | public function __construct(FormName $name, bool $isRootObject, bool $isPolymorphic, mixed $value, ComponentHashmap $tabComponents) |
| 12 | { |
| 13 | $newTabsComponent = []; |
| 14 | $componentMap = []; |
| 15 | foreach ($tabComponents as $key => $component) { |
| 16 | $md5 = 's' . md5((string) $name . ',' . $key); |
| 17 | $newTabsComponent[$key] = $this->makePrototype($md5, $component); |
| 18 | $subName = $newTabsComponent[$key]->attributes['name'] ?? |
| 19 | $newTabsComponent[$key]->attributes['groupName']; |
| 20 | $componentMap[(string) $subName] = $key; |
| 21 | } |
| 22 | |
| 23 | parent::__construct( |
| 24 | [ |
| 25 | 'name' => $name, |
| 26 | 'isRootObject' => $isRootObject, |
| 27 | 'isPolymorphic' => $isPolymorphic, |
| 28 | 'tabs' => array_keys($newTabsComponent), |
| 29 | 'mapping' => $componentMap, |
| 30 | 'value' => $value, |
| 31 | ], |
| 32 | new ComponentHashmap($newTabsComponent) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | public function withName(FormName $name, mixed $value = null): ComponentInterface |
| 37 | { |
| 38 | $item = clone $this; |
| 39 | $item->attributes['name'] = $name; |
| 40 | foreach ($item->childComponents as $key => $component) { |
| 41 | $item->childComponents[$key] = $component->withName($name, $value); |
| 42 | } |
| 43 | return $item; |
| 44 | } |
| 45 | } |