| Conditions | 2 |
| Paths | 2 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | public function index(Request $request, ORMInterface $orm): Response |
||
| 24 | { |
||
| 25 | /** @var TagRepository $tagRepo */ |
||
| 26 | $tagRepo = $orm->getRepository(Tag::class); |
||
| 27 | /** @var PostRepository $postRepo */ |
||
| 28 | $postRepo = $orm->getRepository(Post::class); |
||
| 29 | $label = $request->getAttribute('label', null); |
||
| 30 | $pageNum = (int)$request->getAttribute('page', 1); |
||
| 31 | |||
| 32 | $item = $tagRepo->findByLabel($label); |
||
| 33 | |||
| 34 | if ($item === null) { |
||
| 35 | return $this->responseFactory->createResponse(404); |
||
| 36 | } |
||
| 37 | // preloading of posts |
||
| 38 | $paginator = (new OffsetPaginator($postRepo->findByTag($item->getId()))) |
||
| 39 | ->withPageSize(self::POSTS_PER_PAGE) |
||
| 40 | ->withCurrentPage($pageNum); |
||
| 41 | |||
| 42 | $data = [ |
||
| 43 | 'item' => $item, |
||
| 44 | 'paginator' => $paginator, |
||
| 45 | ]; |
||
| 46 | return $this->render('index', $data); |
||
| 47 | } |
||
| 49 |