Поправил формат ответа

Нужно подумать о конвешн по структурированным массивам
master
Sipachev Igor 3 years ago
parent 333de3fdc8
commit 7f5e04539a
  1. 8
      src/Dto2DataConverter.php
  2. 2
      tests/unit/Converter/FillTest.php

@ -46,8 +46,8 @@ class Dto2DataConverter
if (is_object($value) && is_array($propertyInfo)) { if (is_object($value) && is_array($propertyInfo)) {
$value = $this->convertObjectByMap($value, $propertyInfo, $tags); $value = $this->convertObjectByMap($value, $propertyInfo, $tags);
} elseif (is_iterable($value)) { } elseif (is_iterable($value)) {
$map = is_array($propertyInfo) ? $propertyInfo : null; $childMap = is_array($propertyInfo) ? $propertyInfo : null;
$value = $this->convertArrayByMap($value, $map, $tags); $value = $this->convertArrayByMap($value, $childMap, $tags);
} elseif (!is_scalar($value) && null !== $value) { } elseif (!is_scalar($value) && null !== $value) {
continue; continue;
} }
@ -64,6 +64,8 @@ class Dto2DataConverter
public function convertArrayByMap($data, ?array $map, array $tags = []): ?array public function convertArrayByMap($data, ?array $map, array $tags = []): ?array
{ {
$isAssociative = count($data) && !array_key_exists(0, $data);
$tempValue = []; $tempValue = [];
foreach ($data as $key => $item) { foreach ($data as $key => $item) {
if (is_scalar($item)) { if (is_scalar($item)) {
@ -79,7 +81,7 @@ class Dto2DataConverter
continue; continue;
} }
} }
return $tempValue ?: null; return $tempValue;
} }
protected function grabValue(object $object, $sourceName) protected function grabValue(object $object, $sourceName)

@ -95,7 +95,7 @@ class FillTest extends \Codeception\Test\Unit
"name" => "Sapkovsky" "name" => "Sapkovsky"
] ]
], ],
"authors3" => null, "authors3" => [],
"buy" => [ "buy" => [
"phrase" => "Buy buy!!!", "phrase" => "Buy buy!!!",
"length" => 10, "length" => 10,

Loading…
Cancel
Save