| Conditions | 2 |
| Paths | 2 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | public function index(Request $request, TagRepository $tagRepository, PostRepository $postRepository, ResponseFactoryInterface $responseFactory): Response |
||
| 25 | { |
||
| 26 | $label = $request->getAttribute('label', null); |
||
| 27 | $pageNum = (int)$request->getAttribute('page', 1); |
||
| 28 | $item = $tagRepository->findByLabel($label); |
||
| 29 | |||
| 30 | if ($item === null) { |
||
| 31 | return $responseFactory->createResponse(404); |
||
| 32 | } |
||
| 33 | // preloading of posts |
||
| 34 | $paginator = (new OffsetPaginator($postRepository->findByTag($item->getId()))) |
||
| 35 | ->withPageSize(self::POSTS_PER_PAGE) |
||
| 36 | ->withCurrentPage($pageNum); |
||
| 37 | |||
| 38 | $data = [ |
||
| 39 | 'item' => $item, |
||
| 40 | 'paginator' => $paginator, |
||
| 41 | ]; |
||
| 42 | return $this->viewRenderer->render('index', $data); |
||
| 43 | } |
||
| 45 |