Completed
Push — master ( c698df...2bf777 )
by Michael
03:54
created
src/Michaelc/Voting/STV/Ballot.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
     /**
31 31
      * Constructor
32 32
      *
33
-     * @param array $ranking The ranking of candidates Key being ranking,
33
+     * @param integer[] $ranking The ranking of candidates Key being ranking,
34 34
      *                       value being a candidate id
35 35
      */
36 36
     public function __construct(array $ranking)
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace Michaelc\Voting\STV;
4 4
 
5
-use Michaelc\Voting\STV\Candidate;
6
-
7 5
 class Ballot
8 6
 {
9 7
     /**
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
         if (empty($this->ranking[$level]))
120 120
         {
121
-          return null;
121
+            return null;
122 122
         }
123 123
 
124 124
         return $this->ranking[$level];
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
         if (empty($this->ranking[$level]))
132 132
         {
133
-          return null;
133
+            return null;
134 134
         }
135 135
 
136 136
         return $this->ranking[$level];
Please login to merge, or discard this patch.
src/Michaelc/Voting/STV/VoteHandler.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -6,50 +6,50 @@
 block discarded – undo
6 6
 
7 7
 class VoteHandler
8 8
 {
9
-	protected $election;
10
-	protected $ballots;
11
-
12
-	/**
13
-	 * Constructor
14
-	 *
15
-	 * @param Election $election
16
-	 */
17
-	public function __construct(Election $election)
18
-	{
19
-		$this->election = $election;
20
-		$this->ballots = $this->election->getBallots();
21
-	}
22
-
23
-	public function step($step)
24
-	{
25
-		foreach ($this->ballots as $i => $ballot)
26
-		{
27
-			$weight = $ballot->getWeight();
28
-			$candidate = $ballot->getNextPreference();
29
-			$election->getCandidate($candidate->getId())->addVotes($weight);
30
-			$ballot->setLastUsedLevel(($step - 1));
31
-		}
32
-
33
-		$candidates = $election->getActiveCandidates();
34
-
35
-		foreach ($candidates as $i => $candidate) {
36
-			if ($candidate->getVotes() >= $this->getQuota())
37
-			{
38
-        		$candidate->setState(Candidate::ELECTED);
39
-        		$surplus = $candidate->getVotes() - $quota;
40
-
41
-        		$this->transferVotes($surplus, $candidate);
42
-        	}
43
-		}
44
-	}
45
-
46
-	protected function transferVotes(float $votes, Candidate $candidate)
47
-	{
48
-
49
-	}
50
-
51
-	public function getQuota()
52
-	{
53
-		return floor(($election->getNumBallots() / ($election->getNumSeats() + 1)) + 1);
54
-	}
9
+    protected $election;
10
+    protected $ballots;
11
+
12
+    /**
13
+     * Constructor
14
+     *
15
+     * @param Election $election
16
+     */
17
+    public function __construct(Election $election)
18
+    {
19
+        $this->election = $election;
20
+        $this->ballots = $this->election->getBallots();
21
+    }
22
+
23
+    public function step($step)
24
+    {
25
+        foreach ($this->ballots as $i => $ballot)
26
+        {
27
+            $weight = $ballot->getWeight();
28
+            $candidate = $ballot->getNextPreference();
29
+            $election->getCandidate($candidate->getId())->addVotes($weight);
30
+            $ballot->setLastUsedLevel(($step - 1));
31
+        }
32
+
33
+        $candidates = $election->getActiveCandidates();
34
+
35
+        foreach ($candidates as $i => $candidate) {
36
+            if ($candidate->getVotes() >= $this->getQuota())
37
+            {
38
+                $candidate->setState(Candidate::ELECTED);
39
+                $surplus = $candidate->getVotes() - $quota;
40
+
41
+                $this->transferVotes($surplus, $candidate);
42
+            }
43
+        }
44
+    }
45
+
46
+    protected function transferVotes(float $votes, Candidate $candidate)
47
+    {
48
+
49
+    }
50
+
51
+    public function getQuota()
52
+    {
53
+        return floor(($election->getNumBallots() / ($election->getNumSeats() + 1)) + 1);
54
+    }
55 55
 }
Please login to merge, or discard this patch.