| Conditions | 7 |
| Paths | 18 |
| Total Lines | 53 |
| 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 |
||
| 150 | public function fetchLastRivals() |
||
| 151 | { |
||
| 152 | $player = Yii::app()->player->model; |
||
| 153 | $limit = Yii::app()->params['listPerPage']; |
||
| 154 | |||
| 155 | $res = Yii::app()->db->createCommand() |
||
| 156 | ->select('id, caller, created') |
||
| 157 | ->from('duel') |
||
| 158 | ->where('opponent=:uid', [':uid'=>$player->uid]) |
||
| 159 | ->order('id DESC') |
||
| 160 | ->limit($limit) |
||
| 161 | ->queryAll(); |
||
| 162 | |||
| 163 | $club = new Club(); |
||
| 164 | $duelShiel = new DuelShield(); |
||
| 165 | $cache = []; |
||
| 166 | foreach ($res as $item) { |
||
| 167 | $item['uid'] = $item['caller']; |
||
| 168 | |||
| 169 | if (!isset($cache[$item['uid']])) { |
||
| 170 | $p = Yii::app()->db->createCommand() |
||
| 171 | ->select('user, energy, energy_max, dollar, level, in_club') |
||
| 172 | ->from('main') |
||
| 173 | ->where('uid=:uid', [':uid'=>(int)$item['uid']]) |
||
| 174 | ->queryRow(); |
||
| 175 | if (!is_array($p)) { |
||
| 176 | continue; |
||
| 177 | } |
||
| 178 | |||
| 179 | $cache[$item['uid']] = $p; |
||
| 180 | } else { |
||
| 181 | $p = $cache[$item['uid']]; |
||
| 182 | } |
||
| 183 | |||
| 184 | foreach ($p as $k => $v) { |
||
| 185 | $item[$k] = $v; |
||
| 186 | } |
||
| 187 | |||
| 188 | $duelShiel->uid = $item['uid']; |
||
| 189 | if ($duelShiel->lifeTime > 0) { |
||
| 190 | $item['energy'] = 0; |
||
| 191 | } |
||
| 192 | |||
| 193 | $item['disabled'] = 0; |
||
| 194 | if ($item['energy'] <= $item['energy_max'] / 10) { |
||
| 195 | $item['disabled'] = 1; //low energy |
||
| 196 | } |
||
| 197 | |||
| 198 | $item['prize'] = round($item['dollar'] / 10); |
||
| 199 | $item['clubName'] = $this->getClubName($club, $item['in_club']); |
||
| 200 | $this->opponents[] = $item; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | } |
||
| 204 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.