Passed
Push — master ( 83de64...44197b )
by Anthony
02:43
created

RenderPageController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderPage() 0 12 2
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\Routing\Annotation\Route;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10
class RenderPageController extends AbstractController
11
{
12
    /**
13
     * @Route("/page/{url}", name="page", requirements={"url" = "[a-zA-Z0-9\-\_\/]*"})
14
     * @param string $url
15
     * @return Response
16
     */
17
    public function renderPage(string $url): Response
18
    {
19
        $em = $this->getDoctrine()->getManager();
20
21
        $page = $em->getRepository("RibsAdminBundle:Page")->findOneBy(["url" => $url]);
22
        $navigation = $em->getRepository("RibsAdminBundle:Navigation")->findAllNavigation();
23
24
        if ($page) {
25
            return $this->render("@RibsAdmin/page.html.twig", ["page" => $page, "navigation" => $navigation]);
26
        }
27
28
        throw new NotFoundHttpException("The required page does not exist");
29
    }
30
}
31