From f19133255d13a35a8523bf1ad42233be4d1fd64d Mon Sep 17 00:00:00 2001 From: AlexP Date: Mon, 13 May 2024 00:10:37 +0500 Subject: [PATCH] STA-950 | hotfix restaurants tags --- app/src/Dto/TagDto.php | 12 +++++++++--- app/src/Entity/Restaurants.php | 22 ++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/Dto/TagDto.php b/app/src/Dto/TagDto.php index 42dee2b..58733a0 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 a6208fe..69e614c 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; } } -- GitLab