@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $this->rejectInvalidBallots(); |
| 63 | 63 | |
| 64 | - $this->firstStep(); |
|
| 64 | + $this->firstStep(); |
|
| 65 | 65 | |
| 66 | 66 | $candidates = $this->election->getActiveCandidates(); |
| 67 | 67 | |
| 68 | 68 | while ($this->electedCandidates < $this->election->getWinnersCount()) |
| 69 | 69 | { |
| 70 | - if (!$this->checkCandidates($candidates)) |
|
| 71 | - { |
|
| 72 | - $this->eliminateCandidates($candidates); |
|
| 73 | - } |
|
| 70 | + if (!$this->checkCandidates($candidates)) |
|
| 71 | + { |
|
| 72 | + $this->eliminateCandidates($candidates); |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return $this->election->getElectedCandidates(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | protected function checkCandidates(array &$candidates): bool |
| 101 | 101 | { |
| 102 | - foreach ($candidates as $i => $candidate) |
|
| 102 | + foreach ($candidates as $i => $candidate) |
|
| 103 | 103 | { |
| 104 | 104 | if ($candidate->getVotes() >= $this->quota) |
| 105 | 105 | { |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | if ($candidate !== null) |
| 129 | 129 | { |
| 130 | - $this->election->getCandidate($candidate)->addVotes($weight); |
|
| 131 | - $ballot->incrementLevelUsed(); |
|
| 130 | + $this->election->getCandidate($candidate)->addVotes($weight); |
|
| 131 | + $ballot->incrementLevelUsed(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return $ballot; |
@@ -144,16 +144,16 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | protected function transferSurplusVotes(float $surplus, Candidate $candidate) |
| 146 | 146 | { |
| 147 | - $totalVotes = $candidate->getVotes(); |
|
| 148 | - $candidateId = $candidate->getId(); |
|
| 147 | + $totalVotes = $candidate->getVotes(); |
|
| 148 | + $candidateId = $candidate->getId(); |
|
| 149 | 149 | |
| 150 | - foreach ($this->ballots as $i => $ballot) |
|
| 151 | - { |
|
| 152 | - if ($ballot->getLastChoice() == $candidateId) |
|
| 153 | - { |
|
| 154 | - $this->allocateVotes($ballot, $surplus, $totalVotes); |
|
| 155 | - } |
|
| 156 | - } |
|
| 150 | + foreach ($this->ballots as $i => $ballot) |
|
| 151 | + { |
|
| 152 | + if ($ballot->getLastChoice() == $candidateId) |
|
| 153 | + { |
|
| 154 | + $this->allocateVotes($ballot, $surplus, $totalVotes); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | return; |
| 159 | 159 | } |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function transferEliminatedVotes(Candidate $candidate) |
| 169 | 169 | { |
| 170 | - $candidateId = $candidate->getId(); |
|
| 170 | + $candidateId = $candidate->getId(); |
|
| 171 | 171 | |
| 172 | - foreach ($this->ballots as $i => $ballot) |
|
| 172 | + foreach ($this->ballots as $i => $ballot) |
|
| 173 | 173 | { |
| 174 | - if ($ballot->getLastChoice() == $candidateId) |
|
| 175 | - { |
|
| 176 | - $this->allocateVotes($ballot); |
|
| 177 | - } |
|
| 174 | + if ($ballot->getLastChoice() == $candidateId) |
|
| 175 | + { |
|
| 176 | + $this->allocateVotes($ballot); |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | return; |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | if ($this->electedCandidates < $this->election->getWinnersCount()) |
| 200 | 200 | { |
| 201 | - $surplus = $candidate->getVotes() - $this->quota; |
|
| 202 | - $this->transferSurplusVotes($surplus, $candidate); |
|
| 201 | + $surplus = $candidate->getVotes() - $this->quota; |
|
| 202 | + $this->transferSurplusVotes($surplus, $candidate); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | return; |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function eliminateCandidates(array &$candidates): int |
| 216 | 216 | { |
| 217 | - $minimum = 0; |
|
| 217 | + $minimum = 0; |
|
| 218 | 218 | $minimumCandidates = []; |
| 219 | 219 | |
| 220 | - foreach ($candidates as $i => $candidate) |
|
| 220 | + foreach ($candidates as $i => $candidate) |
|
| 221 | 221 | { |
| 222 | 222 | if ($candidate->getVotes() > $minimum) |
| 223 | 223 | { |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | |
| 234 | 234 | foreach ($minimumCandidates as $minimumCandidate) |
| 235 | 235 | { |
| 236 | - $this->transferEliminatedVotes($minimumCandidate); |
|
| 237 | - $minimumCandidate->setState(Candidate::DEFEATED); |
|
| 236 | + $this->transferEliminatedVotes($minimumCandidate); |
|
| 237 | + $minimumCandidate->setState(Candidate::DEFEATED); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | return count($minimumCandidates); |