Passed
Pull Request — master (#15)
by Stone
05:15
created

TrickController::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller;
4
5
use App\Entity\Trick;
6
use App\Repository\TrickRepository;
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use Symfony\Component\Routing\Annotation\Route;
9
10
class TrickController extends AbstractController
11
{
12
13
    /**
14
     * @var TrickRepository
15
     */
16
    private $repository;
17
18
    public function __construct(TrickRepository $repository)
19
    {
20
        $this->repository = $repository;
21
    }
22
23
    /**
24
     * @Route("/", name="trick.home")
25
     */
26
    public function index()
27
    {
28
        $tricks = $this->repository->findLatestEdited();
29
        return $this->render('trick/index.html.twig', [
30
            'tricks' => $tricks,
31
        ]);
32
    }
33
34
    /**
35
     * @Route("/trick/{id}-{slug}", name="trick.show", requirements={"slug": "[a-z0-9\-]*"})
36
     */
37
    public function show(Trick $trick, string $slug)
38
    {
39
40
        //Checking if slug is equal to the ID. This is for SEO and external links
41
        if ($trick->getSlug() !== $slug) {
42
            return $this->redirectToRoute('trick.show', [
43
                'id' => $trick->getId(),
44
                'slug' => $trick->getSlug()
45
            ], 301);
46
        }
47
48
        return $this->render('trick/show.html.twig', [
49
            'trick' => $trick,
50
        ]);
51
    }
52
53
    /**
54
     * @Route("/search", name="trick.search")
55
     */
56
    public function search()
57
    {
58
        $tricks = $this->repository->findAll();
59
        return $this->render('trick/search.html.twig', [
60
            'tricks' => $tricks,
61
        ]);
62
    }
63
}
64