Completed
Push — master ( 9db26b...a06708 )
by Michael
04:04
created

VoteController::listAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Pagerfanta\Adapter\ArrayAdapter;
6
use Pagerfanta\Adapter\DoctrineORMAdapter;
7
use Pagerfanta\Pagerfanta;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
11
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use AppBundle\Entity\Poll;
15
16
class VoteController extends Controller
17
{
18
    /**
19
     * @Route("/poll", name="polls_list")
20
     */
21 1
    public function listAction(Request $request): Response
22
    {
23 1
        $polls = $this->getPolls($request);
24 1
        $current = $this->getCurrentPolls();
25
26 1
        return $this->render('default/index.html.twig', ['polls' => $polls, 'current' => $current]);
27
    }
28
29
    /**
30
     * Get an array of current polls (objects)
31
     *
32
     * @return array
33
     */
34 1
    protected function getCurrentPolls(): array
35
    {
36 1
    	$currentPolls = $this->getDoctrine()
1 ignored issue
show
Bug introduced by
The method findByActive() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37 1
    		->getRepository('AppBundle:Poll')
38 1
    		->findByActive(true);
39
40 1
    	return $currentPolls;
41
    }
42
43
    /**
44
     * Get pagination object of Polls
45
     *
46
     * @param Request $request
47
     * @return Pagerfanta
48
     */
49 1
    protected function getPolls(Request $request): Pagerfanta
50
    {
51 1
        $polls = $this->getDoctrine()
52 1
            ->getRepository('AppBundle:Poll')
53 1
            ->findAll();
54 1
        $paginator = new Pagerfanta(new ArrayAdapter($polls));
55 1
        $paginator->setMaxPerPage(20);
56 1
        $paginator->setCurrentPage($request->query->get('page', 1), false, true);
57
58 1
        return $paginator;
59
    }
60
}
61