| Total Complexity | 8 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 94.12% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class FormObjectTransformer extends AbstractSerializerRequestTransformer |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * {@inheritdoc} |
||
| 13 | */ |
||
| 14 | 4 | public function transform($formData = [], ContextInterface $context = null): array |
|
| 15 | { |
||
| 16 | 4 | if (empty($formData)) { |
|
| 17 | return []; |
||
| 18 | } |
||
| 19 | |||
| 20 | 4 | if (is_object($formData)) { |
|
| 21 | 1 | return $this->normalizeObject($formData, $context); |
|
| 22 | } |
||
| 23 | |||
| 24 | 3 | array_walk_recursive($formData, [&$this, 'serializeObjects'], $context); |
|
| 25 | |||
| 26 | 3 | return $formData; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Checks if the formData is supported to execute the transformation. |
||
| 31 | * |
||
| 32 | * @param array|object $formData |
||
| 33 | * |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | 4 | public function supports($formData): bool |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param $item |
||
| 43 | * @param $key |
||
| 44 | * @param ContextInterface|null $context |
||
| 45 | */ |
||
| 46 | 3 | protected function serializeObjects(&$item, $key, ContextInterface $context = null) |
|
| 50 | } |
||
| 51 | 3 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param $object |
||
| 55 | * @param ContextInterface|null $context |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | 4 | protected function normalizeObject($object, ContextInterface $context = null) |
|
| 67 |