Simplified mapping of TagInfo objects

This commit is contained in:
Alejandro Celaya 2022-09-08 20:50:11 +02:00
parent 19a9d815eb
commit e6ee4ceae2
3 changed files with 7 additions and 1 deletions

View file

@ -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(...),
);
}

View file

@ -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 [

View file

@ -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,