| Conditions | 12 |
| Paths | 78 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 26 |
| CRAP Score | 12 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 137 | 95 | protected function computeOneVote (Vote $oneVote) : void |
|
| 138 | { |
||
| 139 | 95 | $vote_ranking = $oneVote->getContextualRanking($this->_Election); |
|
|
1 ignored issue
–
show
|
|||
| 140 | |||
| 141 | 95 | $voteWeight = ($this->_Election->isVoteWeightIsAllowed()) ? $oneVote->getWeight() : 1; |
|
| 142 | |||
| 143 | 95 | $vote_candidate_list = []; |
|
| 144 | |||
| 145 | 95 | foreach ($vote_ranking as $rank) : |
|
| 146 | 95 | foreach ($rank as $oneCandidate) : |
|
| 147 | 95 | $vote_candidate_list[] = $oneCandidate; |
|
| 148 | endforeach; |
||
| 149 | endforeach; |
||
| 150 | |||
| 151 | 95 | $done_Candidates = []; |
|
| 152 | |||
| 153 | 95 | foreach ($vote_ranking as $candidates_in_rank) : |
|
| 154 | |||
| 155 | 95 | $candidates_in_rank_keys = []; |
|
| 156 | |||
| 157 | 95 | foreach ($candidates_in_rank as $candidate) : |
|
| 158 | 95 | $candidates_in_rank_keys[] = $this->_Election->getCandidateKey($candidate); |
|
| 159 | endforeach; |
||
| 160 | |||
| 161 | 95 | foreach ($candidates_in_rank as $candidate) : |
|
| 162 | |||
| 163 | 95 | $candidate_key = $this->_Election->getCandidateKey($candidate); |
|
| 164 | |||
| 165 | // Process |
||
| 166 | 95 | foreach ( $vote_candidate_list as $g_Candidate ) : |
|
| 167 | |||
| 168 | 95 | $g_candidate_key = $this->_Election->getCandidateKey($g_Candidate); |
|
| 169 | |||
| 170 | 95 | if ($candidate_key === $g_candidate_key) : |
|
| 171 | 95 | continue; |
|
| 172 | endif; |
||
| 173 | |||
| 174 | // Win & Lose |
||
| 175 | 95 | if ( !in_array($g_candidate_key, $done_Candidates, true) && |
|
| 176 | 95 | !in_array($g_candidate_key, $candidates_in_rank_keys, true) ) : |
|
| 177 | |||
| 178 | 94 | $this->_Pairwise[$candidate_key]['win'][$g_candidate_key] += $voteWeight; |
|
| 179 | 94 | $this->_Pairwise[$g_candidate_key]['lose'][$candidate_key] += $voteWeight; |
|
| 180 | |||
| 181 | 94 | $done_Candidates[] = $candidate_key; |
|
| 182 | |||
| 183 | // Null |
||
| 184 | 95 | elseif (in_array($g_candidate_key, $candidates_in_rank_keys, true)) : |
|
| 185 | 95 | $this->_Pairwise[$candidate_key]['null'][$g_candidate_key] += $voteWeight; |
|
| 186 | endif; |
||
| 187 | |||
| 188 | endforeach; |
||
| 189 | |||
| 190 | endforeach; |
||
| 191 | |||
| 192 | endforeach; |
||
| 193 | 95 | } |
|
| 194 | |||
| 196 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: