Completed
Push — master ( c15895...5432fb )
by Peter
22:43
created

BlogController::showAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
8
class BlogController extends Controller
9
{
10
    /**
11
     * @Route("/blog", name="blog_homepage")
12
     * @return \Symfony\Component\HttpFoundation\Response
13
     */
14
    public function indexAction()
15
    {
16
        $posts = $this->getDoctrine()
17
            ->getRepository('AppBundle:Post')
18
            ->findAll();
19
        
20
        return $this->render(
21
            'blog/index.html.twig',
22
            ['posts' => $posts]
23
        );
24
    }
25
26
    /**
27
     * @Route("/blog/{year}/{month}/{day}/{slug}", name="blog_show", requirements={
28
     *     "year": "\d+",
29
     *     "month": "\d+",
30
     *     "day": "\d+"
31
     * })
32
     * @param $slug
33
     * @return \Symfony\Component\HttpFoundation\Response
34
     */
35
    public function showAction($slug)
36
    {
37
        $post = $this->getDoctrine()
38
            ->getRepository('AppBundle:Post')
39
            ->findOneBySlug($slug);
40
        $em = $this->getDoctrine()->getManager();
0 ignored issues
show
Unused Code introduced by
$em is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
42
        if (!$post) {
43
            throw $this->createNotFoundException(
44
                'No post found for slug '.$slug
45
            );
46
        }
47
48
        return $this->render(
49
            'blog/show.html.twig',
50
            ['post' => $post]
51
        );
52
53
    }
54
}
55