From e6ee4ceae20bc5cfde92b388e862f15843b90718 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 8 Sep 2022 20:50:11 +0200 Subject: [PATCH] Simplified mapping of TagInfo objects --- module/Core/src/Repository/TagRepository.php | 2 +- module/Core/src/Tag/Model/TagInfo.php | 5 +++++ module/Core/src/Tag/Model/TagsParams.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/module/Core/src/Repository/TagRepository.php b/module/Core/src/Repository/TagRepository.php index 2c4e8db6..946cee7e 100644 --- a/module/Core/src/Repository/TagRepository.php +++ b/module/Core/src/Repository/TagRepository.php @@ -110,7 +110,7 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito return map( $this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm)->getResult(), - static fn (array $row) => new TagInfo($row['tag'], (int) $row['shortUrlsCount'], (int) $row['visitsCount']), + TagInfo::fromRawData(...), ); } diff --git a/module/Core/src/Tag/Model/TagInfo.php b/module/Core/src/Tag/Model/TagInfo.php index 8a4f196b..5e71ea5b 100644 --- a/module/Core/src/Tag/Model/TagInfo.php +++ b/module/Core/src/Tag/Model/TagInfo.php @@ -15,6 +15,11 @@ final class TagInfo implements JsonSerializable ) { } + public static function fromRawData(array $data): self + { + return new self($data['tag'], (int) $data['shortUrlsCount'], (int) $data['visitsCount']); + } + public function jsonSerialize(): array { return [ diff --git a/module/Core/src/Tag/Model/TagsParams.php b/module/Core/src/Tag/Model/TagsParams.php index 633fd5f2..3b1d84b2 100644 --- a/module/Core/src/Tag/Model/TagsParams.php +++ b/module/Core/src/Tag/Model/TagsParams.php @@ -14,6 +14,7 @@ final class TagsParams extends AbstractInfinitePaginableListParams private function __construct( public readonly ?string $searchTerm, public readonly Ordering $orderBy, + /** @deprecated */ public readonly bool $withStats, ?int $page, ?int $itemsPerPage,