| Conditions | 13 |
| Paths | 31 |
| Total Lines | 61 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 185 | public static function calculateGamePoints(array $aArray, array $aBaseCol, string $sNameNewCol, string $sColNameToForceZero = ''): array |
||
| 186 | { |
||
| 187 | if (empty($aArray)) { |
||
| 188 | return $aArray; |
||
| 189 | } |
||
| 190 | |||
| 191 | $nameRankCol = array_shift($aBaseCol); |
||
| 192 | $nameEqualCol = array_shift($aBaseCol); |
||
| 193 | |||
| 194 | $nbPlayers = count($aArray); |
||
| 195 | $nbFirstEquals = 1; |
||
| 196 | foreach ($aArray as $aRank) { |
||
| 197 | if ($aRank[$nameRankCol] == 1) { |
||
| 198 | $nbFirstEquals = $aRank[$nameEqualCol]; |
||
| 199 | break; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | //Get formula to first into ranking |
||
| 204 | $a = (-1 / (100 + $nbPlayers - $nbFirstEquals)) + 0.0101 + (log($nbPlayers) / 15000); |
||
| 205 | $b = (atan($nbPlayers - 25) + M_PI_2) * (25000 * ($nbPlayers - 25)) / (200 * M_PI); |
||
| 206 | $f = ceil((10400000 * $a + $b) / ($nbFirstEquals ** (6 / 5))); |
||
| 207 | |||
| 208 | $aF = []; |
||
| 209 | $aF[1] = $f; |
||
| 210 | for ($i = 2; $i <= $nbPlayers; ++$i) { |
||
| 211 | $g = min(0.99, log($i) / (log(71428.6 * $i + 857142.8)) + 0.7); |
||
| 212 | $aF[$i] = $aF[$i - 1] * $g; |
||
| 213 | } |
||
| 214 | |||
| 215 | for ($i = 0; $i < $nbPlayers; ++$i) { |
||
| 216 | //If a column name to force the 0 value is defined, force the 0 value of the new column if the related |
||
| 217 | //column value is 0 |
||
| 218 | if ($sColNameToForceZero !== '' && isset($aArray[$i][$sColNameToForceZero]) && $aArray[$i][$sColNameToForceZero] == 0) { |
||
| 219 | $aArray[$i][$sNameNewCol] = 0; |
||
| 220 | continue; |
||
| 221 | } |
||
| 222 | |||
| 223 | //If firsts |
||
| 224 | if ($aArray[$i][$nameRankCol] == 1) { |
||
| 225 | $aArray[$i][$sNameNewCol] = (int) round($f, 0); |
||
| 226 | continue; |
||
| 227 | } |
||
| 228 | //If non equals |
||
| 229 | if ($aArray[$i][$nameEqualCol] == 1) { |
||
| 230 | $aArray[$i][$sNameNewCol] = (int) round($aF[$aArray[$i][$nameRankCol]], 0); |
||
| 231 | continue; |
||
| 232 | } |
||
| 233 | //If equals (do average of players gives if they weren't tied) |
||
| 234 | $aTiedValues = []; |
||
| 235 | for ($j = 0; $j < $aArray[$i][$nameEqualCol]; ++$j) { |
||
| 236 | $aTiedValues[] = $aF[$aArray[$i][$nameRankCol] + $j]; |
||
| 237 | } |
||
| 238 | $value = round(array_sum($aTiedValues) / count($aTiedValues), 0); |
||
| 239 | for ($j = $i, $nb = $i + count($aTiedValues); $j < $nb; ++$j) { |
||
| 240 | $aArray[$i][$sNameNewCol] = (int) $value; |
||
| 241 | $i++; |
||
| 242 | } |
||
| 243 | $i--; |
||
| 244 | } |
||
| 245 | return $aArray; |
||
| 246 | } |
||
| 248 |