From 11a383b7e5d44392483e5674316b8bb2848c46a5 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 5 Jan 2022 19:25:50 +0100 Subject: [PATCH] Extracted common logic from TagService to a private method --- module/Core/src/Tag/TagService.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/module/Core/src/Tag/TagService.php b/module/Core/src/Tag/TagService.php index dd6bda7e..4da88979 100644 --- a/module/Core/src/Tag/TagService.php +++ b/module/Core/src/Tag/TagService.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Core\Tag; use Doctrine\ORM; use Happyr\DoctrineSpecification\Spec; +use Pagerfanta\Adapter\AdapterInterface; use Pagerfanta\Adapter\ArrayAdapter; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\Tag; @@ -38,9 +39,7 @@ class TagService implements TagServiceInterface new WithApiKeySpecsEnsuringJoin($apiKey), )); - return (new Paginator(new ArrayAdapter($tags))) - ->setMaxPerPage($params->getItemsPerPage()) - ->setCurrentPage($params->getPage()); + return $this->createPaginator(new ArrayAdapter($tags), $params); } /** @@ -52,7 +51,12 @@ class TagService implements TagServiceInterface $repo = $this->em->getRepository(Tag::class); $tagsInfo = $repo->findTagsWithInfo($apiKey); - return (new Paginator(new ArrayAdapter($tagsInfo))) + return $this->createPaginator(new ArrayAdapter($tagsInfo), $params); + } + + private function createPaginator(AdapterInterface $adapter, TagsParams $params): Paginator + { + return (new Paginator($adapter)) ->setMaxPerPage($params->getItemsPerPage()) ->setCurrentPage($params->getPage()); }