Completed
Push — master ( 2e53d7...3a37c9 )
by Michael
04:02
created

VoteController::viewAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\Poll;
6
use Pagerfanta\Adapter\ArrayAdapter;
7
use Pagerfanta\Pagerfanta;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class VoteController extends Controller
14
{
15
    /**
16
     * @Route("/poll", name="polls_list")
17
     */
18 1
    public function listAction(Request $request): Response
19
    {
20 1
        $pollsManager = $this->get('app.poll_manager');
21
22 1
        $polls = $this->getPolls($request);
23 1
        $current = $pollsManager->getCurrentPolls();
24
25 1
        return $this->render('default/index.html.twig', ['polls' => $polls, 'current' => $current]);
26
    }
27
28
    /**
29
     * @Route("/poll/{id}", name="poll_view")
30
     */
31
    public function viewAction(Request $request, Poll $poll): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $poll is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        $pollsMetadata = $this->get('app.poll_manager');
0 ignored issues
show
Unused Code introduced by
$pollsMetadata 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...
34
    }
35
36
    /**
37
     * Get pagination object of Polls
38
     *
39
     * @param Request $request
40
     * @return Pagerfanta
41
     */
42 1
    protected function getPolls(Request $request): Pagerfanta
43
    {
44 1
        $polls = $this->get('app.poll_manager')->getAllPolls();
45 1
        $paginator = new Pagerfanta(new ArrayAdapter($polls));
46 1
        $paginator->setMaxPerPage(20);
47 1
        $paginator->setCurrentPage($request->query->get('page', 1), false, true);
48
49 1
        return $paginator;
50
    }
51
}
52