Passed
Push — master ( 786b21...4a8f5f )
by Stone
06:47 queued 42s
created

ShowTrickController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A show() 0 13 2
1
<?php
2
3
namespace App\Controller\Trick;
4
5
use App\Entity\Trick;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\Routing\Annotation\Route;
8
9
class ShowTrickController extends AbstractController
10
{
11
12
    /**
13
     * @Route("/trick/{id}-{slug}", name="trick.show", requirements={"slug": "[a-z0-9\-]*"})
14
     */
15
    public function show(Trick $trick, string $slug)
16
    {
17
18
        //Checking if slug is equal to the ID. This is for SEO and external links
19
        if ($trick->getSlug() !== $slug) {
20
            return $this->redirectToRoute('trick.show', [
21
                'id' => $trick->getId(),
22
                'slug' => $trick->getSlug()
23
            ], 301);
24
        }
25
26
        return $this->render('trick/show.html.twig', [
27
            'trick' => $trick,
28
        ]);
29
    }
30
31
}
32