@@ -48,7 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | return $this->render( |
| 50 | 50 | 'user/index.html.twig', |
| 51 | - ['votes' => $votes, 'user' => $user,] |
|
| 51 | + ['votes' => $votes, 'user' => $user, ] |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -53,16 +53,16 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function run() |
| 55 | 55 | { |
| 56 | - $this->firstStep(); |
|
| 56 | + $this->firstStep(); |
|
| 57 | 57 | |
| 58 | 58 | $candidates = $this->election->getActiveCandidates(); |
| 59 | 59 | |
| 60 | 60 | while ($electedCandidates < $this->election->getWinners()) |
| 61 | 61 | { |
| 62 | - if (!$this->checkCandidates($candidates)) |
|
| 63 | - { |
|
| 64 | - $this->eliminateCandidates($candidates); |
|
| 65 | - } |
|
| 62 | + if (!$this->checkCandidates($candidates)) |
|
| 63 | + { |
|
| 64 | + $this->eliminateCandidates($candidates); |
|
| 65 | + } |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return $this->election->getElectedCandidates(); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | protected function checkCandidates(array &$candidates): bool |
| 93 | 93 | { |
| 94 | - foreach ($candidates as $i => $candidate) |
|
| 94 | + foreach ($candidates as $i => $candidate) |
|
| 95 | 95 | { |
| 96 | 96 | if ($candidate->getVotes() >= $this->quota) |
| 97 | 97 | { |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | if ($candidate !== null) |
| 121 | 121 | { |
| 122 | - $this->election->getCandidate($candidate->getId())->addVotes($weight); |
|
| 123 | - $ballot->setLevelUsed(($step - 1)); |
|
| 122 | + $this->election->getCandidate($candidate->getId())->addVotes($weight); |
|
| 123 | + $ballot->setLevelUsed(($step - 1)); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $ballot; |
@@ -136,16 +136,16 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function transferSurplusVotes(float $surplus, Candidate $candidate) |
| 138 | 138 | { |
| 139 | - $totalVotes = $candiate->getVotes(); |
|
| 140 | - $candidateId = $candidate->getId(); |
|
| 139 | + $totalVotes = $candiate->getVotes(); |
|
| 140 | + $candidateId = $candidate->getId(); |
|
| 141 | 141 | |
| 142 | - foreach ($this->ballots as $i => $ballot) |
|
| 143 | - { |
|
| 144 | - if ($ballot->getLastChoice()->getId() == $candidateId) |
|
| 145 | - { |
|
| 146 | - $this->allocateVotes($ballot, $surplus, $totalVotes); |
|
| 147 | - } |
|
| 148 | - } |
|
| 142 | + foreach ($this->ballots as $i => $ballot) |
|
| 143 | + { |
|
| 144 | + if ($ballot->getLastChoice()->getId() == $candidateId) |
|
| 145 | + { |
|
| 146 | + $this->allocateVotes($ballot, $surplus, $totalVotes); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | return; |
| 151 | 151 | } |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | protected function transferEliminatedVotes(Candidate $candidate) |
| 161 | 161 | { |
| 162 | - $candidateId = $candidate->getId(); |
|
| 162 | + $candidateId = $candidate->getId(); |
|
| 163 | 163 | |
| 164 | - foreach ($this->ballots as $i => $ballot) |
|
| 164 | + foreach ($this->ballots as $i => $ballot) |
|
| 165 | 165 | { |
| 166 | - if ($ballot->getLastChoice()->getId() == $candidateId) |
|
| 167 | - { |
|
| 168 | - $this->allocateVotes($ballot); |
|
| 169 | - } |
|
| 166 | + if ($ballot->getLastChoice()->getId() == $candidateId) |
|
| 167 | + { |
|
| 168 | + $this->allocateVotes($ballot); |
|
| 169 | + } |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | return; |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if ($this->electedCandidates < $this->election->getWinnersCount()) |
| 192 | 192 | { |
| 193 | - $surplus = $candidate->getVotes() - $this->quota; |
|
| 194 | - $this->transferVotes($surplus, $candidate); |
|
| 193 | + $surplus = $candidate->getVotes() - $this->quota; |
|
| 194 | + $this->transferVotes($surplus, $candidate); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return; |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | protected function eliminateCandidates(array &$candidates): int |
| 208 | 208 | { |
| 209 | - $minimum = 0; |
|
| 209 | + $minimum = 0; |
|
| 210 | 210 | |
| 211 | - foreach ($candidates as $i => $candidate) |
|
| 211 | + foreach ($candidates as $i => $candidate) |
|
| 212 | 212 | { |
| 213 | 213 | if ($candidate->getVotes() > $minimum) |
| 214 | 214 | { |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | foreach($minimumCandidates as $minimumCandidate) |
| 226 | 226 | { |
| 227 | - $this->transferEliminatedVotes($minimumCandidate); |
|
| 228 | - $minimumCandidate->setState(Candidate::DEFEATED); |
|
| 227 | + $this->transferEliminatedVotes($minimumCandidate); |
|
| 228 | + $minimumCandidate->setState(Candidate::DEFEATED); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return count($minimumCandidates); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * candidate votes) |
| 113 | 113 | * @return Ballot The same ballot passed in modified |
| 114 | 114 | */ |
| 115 | - protected function allocateVotes(Ballot &$ballot, float $multiplier = 1.0, float $divisor = 1.0): Ballot |
|
| 115 | + protected function allocateVotes(Ballot & $ballot, float $multiplier = 1.0, float $divisor = 1.0): Ballot |
|
| 116 | 116 | { |
| 117 | 117 | $weight = $ballot->setWeight(($ballot->getWeight() * $multiplier) / $divisor); |
| 118 | 118 | $candidate = $ballot->getNextChoice(); |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - foreach($minimumCandidates as $minimumCandidate) |
|
| 225 | + foreach ($minimumCandidates as $minimumCandidate) |
|
| 226 | 226 | { |
| 227 | 227 | $this->transferEliminatedVotes($minimumCandidate); |
| 228 | 228 | $minimumCandidate->setState(Candidate::DEFEATED); |
@@ -215,8 +215,7 @@ |
||
| 215 | 215 | $minimum = $candidate->getVotes(); |
| 216 | 216 | unset($minimumCandidates); |
| 217 | 217 | $minimumCandidates[] = $candidate; |
| 218 | - } |
|
| 219 | - elseif ($candidate->getVotes() == $minimum) |
|
| 218 | + } elseif ($candidate->getVotes() == $minimum) |
|
| 220 | 219 | { |
| 221 | 220 | $minimumCandidates[] = $candidate; |
| 222 | 221 | } |