| Conditions | 9 |
| Paths | 5 |
| Total Lines | 60 |
| Code Lines | 48 |
| 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 |
||
| 71 | public function rankRefresh() |
||
| 72 | { |
||
| 73 | $ret=[]; |
||
| 74 | $participants=$this->participants(); |
||
| 75 | $contest_problems=$this->problems; |
||
| 76 | $contest_problems->load('problem'); |
||
| 77 | if ($this->rule==1) { |
||
| 78 | // ACM/ICPC Mode |
||
| 79 | foreach ($participants as $participant) { |
||
| 80 | $prob_detail=[]; |
||
| 81 | $totPen=0; |
||
| 82 | $totScore=0; |
||
| 83 | foreach ($contest_problems as $contest_problem) { |
||
| 84 | $prob_stat=$contest_problem->userStatus($participant); |
||
| 85 | $prob_detail[]=[ |
||
| 86 | 'ncode'=>$contest_problem->ncode, |
||
| 87 | 'pid'=>$contest_problem->pid, |
||
| 88 | 'color'=>$prob_stat['color'], |
||
| 89 | 'wrong_doings'=>$prob_stat['wrong_doings'], |
||
| 90 | 'solved_time_parsed'=>$prob_stat['solved_time_parsed'] |
||
| 91 | ]; |
||
| 92 | if ($prob_stat['solved']) { |
||
| 93 | $totPen+=$prob_stat['wrong_doings'] * 20; |
||
| 94 | $totPen+=$prob_stat['solved_time'] / 60; |
||
| 95 | $totScore+=$prob_stat['solved']; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $ret[]=[ |
||
| 99 | "uid" => $participant->id, |
||
| 100 | "name" => $participant->name, |
||
| 101 | "nick_name" => DB::table("group_member")->where([ |
||
| 102 | "uid" => $participant->id, |
||
| 103 | "gid" => $this->group->gid |
||
| 104 | ])->where("role", ">", 0)->first()["nick_name"] ?? '', |
||
| 105 | "score" => $totScore, |
||
| 106 | "penalty" => $totPen, |
||
| 107 | "problem_detail" => $prob_detail |
||
| 108 | ]; |
||
| 109 | } |
||
| 110 | usort($ret, function($a, $b) { |
||
| 111 | if ($a["score"]==$b["score"]) { |
||
| 112 | if ($a["penalty"]==$b["penalty"]) { |
||
| 113 | return 0; |
||
| 114 | } elseif (($a["penalty"]>$b["penalty"])) { |
||
| 115 | return 1; |
||
| 116 | } else { |
||
| 117 | return -1; |
||
| 118 | } |
||
| 119 | } elseif ($a["score"]>$b["score"]) { |
||
| 120 | return -1; |
||
| 121 | } else { |
||
| 122 | return 1; |
||
| 123 | } |
||
| 124 | }); |
||
| 125 | Cache::tags(['contest', 'rank'])->put($this->cid, $ret, 60); |
||
| 126 | return $ret; |
||
| 127 | } else { |
||
| 128 | // IO Mode |
||
| 129 | $c=new OutdatedContestModel(); |
||
| 130 | return $c->contestRankCache($this->cid); |
||
| 131 | } |
||
| 190 |