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