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

ShowTrickController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
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