Passed
Push — master ( d0e34d...8ca257 )
by Matt
04:21
created

WanderController::feed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller\Wander;
4
5
use App\Entity\Wander;
6
use App\Repository\WanderRepository;
7
use App\Service\SettingsService;
8
use Knp\Component\Pager\PaginatorInterface;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
15
class WanderController extends AbstractController
16
{
17
    /**
18
     * @Route("/wanders", name="wanders_index", methods={"GET"})
19
     */
20
    public function index(
21
        Request $request,
22
        WanderRepository $wanderRepository,
23
        PaginatorInterface $paginator
24
        ): Response
25
    {
26
        // Customise the query to add an imageCount built-in so we can efficiently
27
        // (and at all :) ) sort it in our paginator.
28
        $qb = $wanderRepository
29
            ->standardQueryBuilder()
30
            ->select('w AS wander')
31
            ->addSelect('COUNT(i) AS imageCount')
32
            ->leftJoin('w.images', 'i')
33
            ->groupBy('w');
34
35
        $query = $qb->getQuery();
36
37
        $pagination = $paginator->paginate(
38
            $query,
39
            $request->query->getInt('page', 1),
40
            20 // Items per page
41
        );
42
43
        return $this->render('wander/index.html.twig', [
44
            'pagination' => $pagination
45
        ]);
46
    }
47
48
    /**
49
     *
50
     * RSS, etc. feeds
51
     *
52
     * @Route(
53
     *  "/feed.{!_format}",
54
     *  name="feed",
55
     *  methods={"GET"},
56
     *  format="rss2",
57
     *  requirements={
58
     *      "_format": "rss2"
59
     *  }
60
     * )
61
     */
62
    public function feed(
63
        Request $request,
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
        /** @scrutinizer ignore-unused */ Request $request,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
        WanderRepository $wanderRepository
65
    ): Response
66
    {
67
        $qb = $wanderRepository
68
            ->standardQueryBuilder()
69
            ->setMaxResults(20);
70
71
        $wanders = $qb->getQuery()->getResult();
72
73
        return $this->render('wander/feed.rss2.twig', [
74
            'wanders' => $wanders
75
        ]);
76
    }
77
78
    /**
79
     * @Route("/wanders/{id}", name="wanders_show", methods={"GET"})
80
     */
81
    public function show(Wander $wander): Response
82
    {
83
        return $this->render('/wander/show.html.twig', [
84
            'wander' => $wander,
85
        ]);
86
    }
87
}