| Conditions | 2 |
| Paths | 2 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | public function index(Request $request, ORMInterface $orm): Response |
||
| 20 | { |
||
| 21 | /** @var TagRepository $tagRepo */ |
||
| 22 | $tagRepo = $orm->getRepository(Tag::class); |
||
| 23 | /** @var PostRepository $postRepo */ |
||
| 24 | $postRepo = $orm->getRepository(Post::class); |
||
| 25 | $label = $request->getAttribute('label', null); |
||
| 26 | $pageNum = (int)$request->getAttribute('page', 1); |
||
| 27 | |||
| 28 | $item = $tagRepo->findByLabel($label); |
||
| 29 | |||
| 30 | if ($item === null) { |
||
| 31 | return $this->responseFactory->createResponse(404); |
||
| 32 | } |
||
| 33 | // preloading of posts |
||
| 34 | $paginator = (new OffsetPaginator($postRepo->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->render('index', $data); |
||
| 43 | } |
||
| 45 |