| Total Complexity | 56 |
| Total Lines | 338 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like BoardController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BoardController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class BoardController extends Controller |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Redirect the Contest Board Page. |
||
| 19 | * |
||
| 20 | * @return Response |
||
|
|
|||
| 21 | */ |
||
| 22 | public function board($cid) |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Show the Contest Challenge Page. |
||
| 29 | * |
||
| 30 | * @return Response |
||
| 31 | */ |
||
| 32 | public function challenge($cid) |
||
| 33 | { |
||
| 34 | $contestModel=new ContestModel(); |
||
| 35 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 36 | $basicInfo=$contestModel->basic($cid); |
||
| 37 | if (!$clearance || time() < strtotime($basicInfo['begin_time'])) { |
||
| 38 | if($clearance == 3){ |
||
| 39 | return Redirect::route('contest.admin', ['cid' => $cid]); |
||
| 40 | }else{ |
||
| 41 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | $contest_name=$contestModel->contestName($cid); |
||
| 45 | $contest_rule=$contestModel->contestRule($cid); |
||
| 46 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 47 | $remainingTime=$contestModel->remainingTime($cid); |
||
| 48 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 49 | $clarificationList=$contestModel->getLatestClarification($cid); |
||
| 50 | if ($remainingTime<=0) { |
||
| 51 | $remainingTime=0; |
||
| 52 | } |
||
| 53 | if($basicInfo['public'] && !$basicInfo['audit_status']){ |
||
| 54 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 55 | } |
||
| 56 | return view('contest.board.challenge', [ |
||
| 57 | 'page_title'=>"Challenge", |
||
| 58 | 'navigation' => "Contest", |
||
| 59 | 'site_title'=>$contest_name, |
||
| 60 | 'cid'=>$cid, |
||
| 61 | 'contest_name'=>$contest_name, |
||
| 62 | 'contest_rule'=>$contest_rule, |
||
| 63 | 'problem_set'=> $problemSet, |
||
| 64 | 'remaining_time'=>$remainingTime, |
||
| 65 | 'custom_info' => $customInfo, |
||
| 66 | 'clarification_list' => $clarificationList, |
||
| 67 | 'clearance'=> $clearance, |
||
| 68 | 'basic'=>$basicInfo, |
||
| 69 | ]); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Show the Contest Editor Page. |
||
| 74 | * |
||
| 75 | * @return Response |
||
| 76 | */ |
||
| 77 | public function editor($cid, $ncode) |
||
| 78 | { |
||
| 79 | $contestModel=new ContestModel(); |
||
| 80 | $problemModel=new ProblemModel(); |
||
| 81 | $compilerModel=new CompilerModel(); |
||
| 82 | $submissionModel=new SubmissionModel(); |
||
| 83 | $accountModel=new AccountModel(); |
||
| 84 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 85 | $basicInfo=$contestModel->basic($cid); |
||
| 86 | if (!$clearance || time() < strtotime($basicInfo['begin_time'])) { |
||
| 87 | if($clearance == 3){ |
||
| 88 | return Redirect::route('contest.admin', ['cid' => $cid]); |
||
| 89 | }else{ |
||
| 90 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | $basicInfo=$contestModel->basic($cid); |
||
| 94 | if($basicInfo['public'] && !$basicInfo['audit_status']){ |
||
| 95 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 96 | } |
||
| 97 | $contest_name=$contestModel->contestName($cid); |
||
| 98 | $contest_rule=$contestModel->rule($cid); |
||
| 99 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 100 | $pid=$contestModel->getPid($cid, $ncode); |
||
| 101 | if (empty($pid)) { |
||
| 102 | return Redirect::route('contest.board', ['cid' => $cid]); |
||
| 103 | } |
||
| 104 | $pcode=$problemModel->pcode($pid); |
||
| 105 | |||
| 106 | $prob_detail=$problemModel->detail($pcode, $cid); |
||
| 107 | if ($problemModel->isBlocked($prob_detail["pid"], $cid)) { |
||
| 108 | return abort('403'); |
||
| 109 | } |
||
| 110 | $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]); |
||
| 111 | $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid); |
||
| 112 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 113 | $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid); |
||
| 114 | $pref=$compiler_pref["pref"]; |
||
| 115 | $submit_code=$compiler_pref["code"]; |
||
| 116 | $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]); |
||
| 117 | |||
| 118 | if (empty($prob_status)) { |
||
| 119 | $prob_status=[ |
||
| 120 | "verdict"=>"NOT SUBMIT", |
||
| 121 | "color"=>"" |
||
| 122 | ]; |
||
| 123 | } |
||
| 124 | |||
| 125 | $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width'); |
||
| 126 | if(empty($editor_left_width)) $editor_left_width='40'; |
||
| 127 | |||
| 128 | return view('contest.board.editor', [ |
||
| 129 | 'page_title'=>"Problem Detail", |
||
| 130 | 'navigation' => "Contest", |
||
| 131 | 'site_title'=>$contest_name, |
||
| 132 | 'contest_name'=>$contest_name, |
||
| 133 | 'cid'=> $cid, |
||
| 134 | 'detail' => $prob_detail, |
||
| 135 | 'compiler_list' => $compiler_list, |
||
| 136 | 'status' => $prob_status, |
||
| 137 | 'pref' => $pref<0 ? 0 : $pref, |
||
| 138 | 'submit_code' => $submit_code, |
||
| 139 | 'contest_mode' => true, |
||
| 140 | 'contest_ended' => $contest_ended, |
||
| 141 | 'ncode' => $ncode, |
||
| 142 | 'contest_rule' => $contest_rule, |
||
| 143 | 'problem_set' => $problemSet, |
||
| 144 | 'clearance' => $clearance, |
||
| 145 | 'oj_detail' => $oj_detail, |
||
| 146 | 'editor_left_width'=>$editor_left_width, |
||
| 147 | ]); |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Show the Contest Rank Page. |
||
| 152 | * |
||
| 153 | * @return Response |
||
| 154 | */ |
||
| 155 | public function rank($cid) |
||
| 156 | { |
||
| 157 | $contestModel=new ContestModel(); |
||
| 158 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 159 | $basicInfo=$contestModel->basic($cid); |
||
| 160 | if (!$clearance || time() < strtotime($basicInfo['begin_time'])) { |
||
| 161 | if($clearance == 3){ |
||
| 162 | return Redirect::route('contest.admin', ['cid' => $cid]); |
||
| 163 | }else{ |
||
| 164 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | $basicInfo=$contestModel->basic($cid); |
||
| 168 | if($basicInfo['public'] && !$basicInfo['audit_status']){ |
||
| 169 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 170 | } |
||
| 171 | $contest_name=$contestModel->contestName($cid); |
||
| 172 | $contest_rule=$contestModel->contestRule($cid); |
||
| 173 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 174 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 175 | $contestRank=$contestModel->contestRank($cid, Auth::user()->id); |
||
| 176 | |||
| 177 | // To determine the ranking |
||
| 178 | foreach ($contestRank as $i => &$r) { |
||
| 179 | if($i != 0) { |
||
| 180 | if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){ |
||
| 181 | $r['rank'] = $contestRank[$i-1]['rank']; |
||
| 182 | }else{ |
||
| 183 | $r['rank'] = $i + 1; |
||
| 184 | } |
||
| 185 | }else{ |
||
| 186 | $r['rank'] = 1; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | $rankFrozen=$contestModel->isFrozen($cid); |
||
| 190 | $frozenTime=$contestModel->frozenTime($cid); |
||
| 191 | return view('contest.board.rank', [ |
||
| 192 | 'page_title'=>"Rank", |
||
| 193 | 'navigation' => "Contest", |
||
| 194 | 'site_title'=>$contest_name, |
||
| 195 | 'contest_name'=>$contest_name, |
||
| 196 | 'contest_rule'=>$contest_rule, |
||
| 197 | 'cid'=>$cid, |
||
| 198 | 'problem_set'=>$problemSet, |
||
| 199 | 'custom_info' => $customInfo, |
||
| 200 | 'contest_rank' => $contestRank, |
||
| 201 | 'rank_frozen' => $rankFrozen, |
||
| 202 | 'frozen_time' => $frozenTime, |
||
| 203 | 'clearance'=> $clearance, |
||
| 204 | 'basic'=>$basicInfo, |
||
| 205 | ]); |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Show the Contest Status Page. |
||
| 210 | * |
||
| 211 | * @return Response |
||
| 212 | */ |
||
| 213 | public function status(Request $request) |
||
| 252 | ]); |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Show the Contest Clarification Page. |
||
| 257 | * |
||
| 258 | * @return Response |
||
| 259 | */ |
||
| 260 | public function clarification($cid) |
||
| 290 | ]); |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Show the Contest Print Page. |
||
| 295 | * |
||
| 296 | * @return Response |
||
| 297 | */ |
||
| 298 | public function print($cid) |
||
| 324 | ]); |
||
| 325 | } |
||
| 326 | |||
| 327 | public function analysis($cid){ |
||
| 356 |