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 |
||
49 | public function rankRefresh() |
||
50 | { |
||
51 | $ret = []; |
||
52 | $participants = $this->participants(); |
||
53 | $contest_problems = $this->problems; |
||
54 | $contest_problems->load('problem'); |
||
55 | if($this->rule == 1){ |
||
56 | // ACM/ICPC Mode |
||
57 | foreach ($participants as $participant) { |
||
58 | $prob_detail=[]; |
||
59 | $totPen=0; |
||
60 | $totScore=0; |
||
61 | foreach ($contest_problems as $contest_problem) { |
||
62 | $prob_stat = $contest_problem->userStatus($participant); |
||
63 | $prob_detail[]=[ |
||
64 | 'ncode'=>$contest_problem->ncode, |
||
65 | 'pid'=>$contest_problem->pid, |
||
66 | 'color'=>$prob_stat['color'], |
||
67 | 'wrong_doings'=>$prob_stat['wrong_doings'], |
||
68 | 'solved_time_parsed'=>$prob_stat['solved_time_parsed'] |
||
69 | ]; |
||
70 | if ($prob_stat['solved']) { |
||
71 | $totPen+=$prob_stat['wrong_doings'] * 20; |
||
72 | $totPen+=$prob_stat['solved_time'] / 60; |
||
73 | $totScore+=$prob_stat['solved']; |
||
74 | } |
||
75 | } |
||
76 | $ret[]=[ |
||
77 | "uid" => $participant->id, |
||
78 | "name" => $participant->name, |
||
79 | "nick_name" => DB::table("group_member")->where([ |
||
80 | "uid" => $participant->id, |
||
81 | "gid" => $this->group->gid |
||
82 | ])->where("role", ">", 0)->first()["nick_name"] ?? '', |
||
83 | "score" => $totScore, |
||
84 | "penalty" => $totPen, |
||
85 | "problem_detail" => $prob_detail |
||
86 | ]; |
||
87 | } |
||
88 | usort($ret, function ($a, $b) { |
||
89 | if ($a["score"]==$b["score"]) { |
||
90 | if ($a["penalty"]==$b["penalty"]) { |
||
91 | return 0; |
||
92 | } elseif (($a["penalty"]>$b["penalty"])) { |
||
93 | return 1; |
||
94 | } else { |
||
95 | return -1; |
||
96 | } |
||
97 | } elseif ($a["score"]>$b["score"]) { |
||
98 | return -1; |
||
99 | } else { |
||
100 | return 1; |
||
101 | } |
||
102 | }); |
||
103 | Cache::tags(['contest', 'rank'])->put($this->cid, $ret, 60); |
||
104 | return $ret; |
||
105 | }else{ |
||
106 | // IO Mode |
||
107 | $c = new OutdatedContestModel(); |
||
108 | return $c->contestRankCache($this->cid); |
||
109 | } |
||
133 |