| Conditions | 10 |
| Paths | 129 |
| Total Lines | 56 |
| Code Lines | 30 |
| 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 |
||
| 105 | public function calculate(){ |
||
| 106 | if(empty($this->contestants)){ |
||
| 107 | return; |
||
| 108 | } |
||
| 109 | |||
| 110 | // recalc rank |
||
| 111 | $this->reassignRank(); |
||
| 112 | |||
| 113 | foreach($this->contestants as &$member){ |
||
| 114 | $member["seed"] = 1.0; |
||
| 115 | foreach($this->contestants as $other){ |
||
| 116 | if($member["uid"] != $other["uid"]){ |
||
| 117 | $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | unset($member); |
||
| 122 | |||
| 123 | foreach($this->contestants as &$contestant){ |
||
| 124 | $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
||
| 125 | $contestant["needRating"] = $this->getRatingToRank($midRank); |
||
| 126 | $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
||
| 127 | } |
||
| 128 | unset($contestant); |
||
| 129 | |||
| 130 | $this->sort("rating"); |
||
| 131 | |||
| 132 | // DO some adjuct |
||
| 133 | // Total sum should not be more than ZERO. |
||
| 134 | $sum = 0; |
||
| 135 | |||
| 136 | foreach($this->contestants as $contestant){ |
||
| 137 | $sum += $contestant["delta"]; |
||
| 138 | } |
||
| 139 | $inc = -floor($sum / $this->totParticipants) - 1; |
||
| 140 | foreach($this->contestants as &$contestant){ |
||
| 141 | $contestant["delta"] += $inc; |
||
| 142 | } |
||
| 143 | unset($contestant); |
||
| 144 | |||
| 145 | // Sum of top-4*sqrt should be adjusted to ZERO. |
||
| 146 | |||
| 147 | $sum = 0; |
||
| 148 | $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
||
| 149 | |||
| 150 | for($i=0;$i<$zeroSumCount;$i++){ |
||
| 151 | $sum += $this->contestants[$i]["delta"]; |
||
| 152 | } |
||
| 153 | |||
| 154 | $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
||
| 155 | |||
| 156 | for($i=0;$i<$zeroSumCount;$i++){ |
||
| 157 | $this->contestants[$i]["delta"] += $inc; |
||
| 158 | } |
||
| 159 | |||
| 160 | return $this->validateDeltas(); |
||
| 161 | } |
||
| 208 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.