diff --git a/app/src/Dto/TagDto.php b/app/src/Dto/TagDto.php index 42dee2b9d96b142348e5634276fee9f8e4edadf5..58733a0903ba665cec78915d30c9d134323c5ccc 100644 --- a/app/src/Dto/TagDto.php +++ b/app/src/Dto/TagDto.php @@ -4,8 +4,14 @@ namespace App\Dto; class TagDto implements DtoInterface { - public string $name; + /** + * @param string $name + * @param DtoCollection $list + */ + public function __construct( + public string $name, - /** @var DtoCollection */ - public DtoCollection $list; + /** @var DtoCollection */ + public DtoCollection $list, + ) {} } diff --git a/app/src/Entity/Restaurants.php b/app/src/Entity/Restaurants.php index a6208fe15ca9da7cc8fa7e30a1878e57714b67f5..69e614c20255091b2883c896f6c1067d168f6182 100644 --- a/app/src/Entity/Restaurants.php +++ b/app/src/Entity/Restaurants.php @@ -495,19 +495,13 @@ class Restaurants implements PrototypeElementDto ) ); - return new DtoCollection( - TagDto::class, - $jsonCollection - ->map(function(array $tag) { - $tagDto = new TagDto(); - $tagDto->name = key($tag); - $tagDto->list = new DtoCollection( - 'string', - $tag - ); - return $tagDto; - }) - ->toArray() - ); + $tagCollection = new DtoCollection(TagDto::class); + foreach ($jsonCollection as $name => $jsonItem) { + $tagCollection->add( + new TagDto($name, new DtoCollection('string', $jsonItem)) + ); + } + + return $tagCollection; } }