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