Completed
Push — master ( 7611a4...c52643 )
by Michael
03:20
created

PollManager::generateResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

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 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Utils;
4
5
use AppBundle\Entity\{
6
	Choice, Poll, PollType
7
};
8
use Doctrine\Common\Persistence\ManagerRegistry;
9
10
class PollManager
11
{
12
    protected $doctrineRegistry;
13
    protected $electionManager;
14
15
	/**
16
	 * Constructor.
17
	 *
18
	 * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrineRegistry
19 1
	 * @param \AppBundle\Utils\ElectionManager             $electionManager
20
	 */
21 1
	public function __construct(ManagerRegistry $doctrineRegistry, ElectionManager $electionManager)
22 1
    {
23 1
        $this->doctrineRegistry = $doctrineRegistry;
24 1
        $this->electionManager = $electionManager;
25
    }
26
27
	public function getPolls($sort, boolean $current = false): array
0 ignored issues
show
Unused Code introduced by
The parameter $sort 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...
28
	{
29
		// TODO: Implement sorts and getting polls from db
30
31 1
		if ($current) {
32
			return $this->getCurrentPolls();
33 1
		}
34
35 1
		return [];
36
	}
37
38
    /**
39
     * Get an array of current polls (objects).
40
     *
41
     * @return array
42
     */
43
    public function getCurrentPolls(): array
44
    {
45
	    $currentPolls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findByActive(true);
46
47
        return $currentPolls;
48
    }
49
50
    /**
51
     * Get an array of eligible votes.
52
     *
53
     * @param AppBundle/Entity/PollType $type
0 ignored issues
show
Documentation introduced by
The doc-type AppBundle/Entity/PollType could not be parsed: Unknown type name "AppBundle/Entity/PollType" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
54
     *
55 1
     * @return array
56
     */
57 1
    public function getEligibleVoters(PollType $type): array
0 ignored issues
show
Unused Code introduced by
The parameter $type 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...
58
    {
59 1
        return [];
60
    }
61
62
    /**
63
     * Get an array of all polls (objects).
64
     *
65
     * @return array
66
     */
67
    public function getAllPolls(): array
68
    {
69
	    $polls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findAll();
70
71
        return $polls;
72
    }
73
74
    /**
75
     * Get poll statistics.
76
     *
77
     * @param Poll $poll
78
     *
79
     * @return array
80
     */
81
    public function getPollStats(Poll $poll): array
0 ignored issues
show
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...
82
    {
83
        // If Poll is election then reject
84
85
        // Get standard stats
86
        return [];
87
    }
88
89
	/**
90
	 * Get the result of the poll (in terms of a choice).
91
	 *
92
	 * @param Poll $poll
93
	 *
94
	 * @return \AppBundle\Entity\Choice
95
	 */
96
    public function getPollResult(Poll $poll): Choice
0 ignored issues
show
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...
97
    {
98
        // If election then call Election Manager
99
100
        // Calculate winning choice
101
        return;
102
    }
103
104
    public function getStandardPollVotes(Poll $poll): array
0 ignored issues
show
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...
105
    {
106
        return [];
107
    }
108
109
    public function markPollClosed(Poll $poll)
110
    {
111
	    $poll->setActive(false);
112
	    $result = $this->generateResult($poll);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->generateResult($poll) (which targets AppBundle\Utils\PollManager::generateResult()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
113
114
	    return $result;
115
    }
116
117
	public function generateResult(Poll $poll)
0 ignored issues
show
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...
118
	{
119
120
    }
121
}
122