BlogController::indexAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * Symfony SI blog.
11
 *
12
 * @Route("/blog")
13
 */
14
class BlogController extends Controller
15
{
16
    /**
17
     * @Route("", name="blog_homepage")
18
     * @return Response
19
     */
20
    public function indexAction()
21
    {
22
        $posts = $this->get('AppBundle\Repository\PostRepository')->findAll();
23
24
        return $this->render(
25
            'blog/index.html.twig',
26
            ['posts' => $posts]
27
        );
28
    }
29
30
    /**
31
     * @Route("/{year}/{month}/{day}/{num}/{slug}", name="blog_show", requirements={
32
     *     "year": "\d+",
33
     *     "month": "\d+",
34
     *     "day": "\d+",
35
     *     "num": "\d+"
36
     * })
37
     * @param int $year
38
     * @param int $month
39
     * @param int $day
40
     * @param int $num
41
     * @param string $slug
42
     * @return Response
43
     */
44
    public function showAction($year, $month, $day, $num, $slug)
45
    {
46
        $post = $this->get('AppBundle\Repository\PostRepository')->findOneBy([
47
            'year' => $year,
48
            'month' => $month,
49
            'day' => $day,
50
            'num' => $num,
51
            'slug' => $slug
52
        ]);
53
54
        $sidebarPosts = $this->get('AppBundle\Repository\PostRepository')->findLatest();
55
56
        if (!$post) {
57
            throw $this->createNotFoundException(
58
                'No post found for slug '.$slug
59
            );
60
        }
61
62
        return $this->render(
63
            'blog/show.html.twig',
64
            ['post' => $post, 'sidebar_posts' => $sidebarPosts]
65
        );
66
    }
67
}
68