| Total Complexity | 43 |
| Total Lines | 406 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ContestController 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 ContestController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class ContestController extends Controller |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Show the Contest Page. |
||
| 23 | * |
||
| 24 | * @return Response |
||
|
|
|||
| 25 | */ |
||
| 26 | public function index(Request $request) |
||
| 61 | ]); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Show the Contest Detail Page. |
||
| 67 | * |
||
| 68 | * @return Response |
||
| 69 | */ |
||
| 70 | public function detail($cid) |
||
| 95 | ]); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Redirect the Contest Board Page. |
||
| 100 | * |
||
| 101 | * @return Response |
||
| 102 | */ |
||
| 103 | public function board($cid) |
||
| 104 | { |
||
| 105 | return Redirect::route('contest.challenge', ['cid' => $cid]); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Show the Contest Challenge Page. |
||
| 110 | * |
||
| 111 | * @return Response |
||
| 112 | */ |
||
| 113 | public function challenge($cid) |
||
| 114 | { |
||
| 115 | $contestModel=new ContestModel(); |
||
| 116 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 117 | if (!$clearance) { |
||
| 118 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 119 | } |
||
| 120 | $contest_name=$contestModel->contestName($cid); |
||
| 121 | $contest_rule=$contestModel->contestRule($cid); |
||
| 122 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 123 | $remainingTime=$contestModel->remainingTime($cid); |
||
| 124 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 125 | $clarificationList=$contestModel->getLatestClarification($cid); |
||
| 126 | $basicInfo=$contestModel->basic($cid); |
||
| 127 | if ($remainingTime<=0) { |
||
| 128 | $remainingTime=0; |
||
| 129 | } |
||
| 130 | return view('contest.board.challenge', [ |
||
| 131 | 'page_title'=>"Challenge", |
||
| 132 | 'navigation' => "Contest", |
||
| 133 | 'site_title'=>$contest_name, |
||
| 134 | 'cid'=>$cid, |
||
| 135 | 'contest_name'=>$contest_name, |
||
| 136 | 'contest_rule'=>$contest_rule, |
||
| 137 | 'problem_set'=> $problemSet, |
||
| 138 | 'remaining_time'=>$remainingTime, |
||
| 139 | 'custom_info' => $customInfo, |
||
| 140 | 'clarification_list' => $clarificationList, |
||
| 141 | 'clearance'=> $clearance, |
||
| 142 | 'basic'=>$basicInfo, |
||
| 143 | ]); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Show the Contest Editor Page. |
||
| 148 | * |
||
| 149 | * @return Response |
||
| 150 | */ |
||
| 151 | public function editor($cid, $ncode) |
||
| 152 | { |
||
| 153 | $contestModel=new ContestModel(); |
||
| 154 | $problemModel=new ProblemModel(); |
||
| 155 | $compilerModel=new CompilerModel(); |
||
| 156 | $submissionModel=new SubmissionModel(); |
||
| 157 | $accountModel=new AccountModel(); |
||
| 158 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 159 | if (!$clearance) { |
||
| 160 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 161 | } |
||
| 162 | $contest_name=$contestModel->contestName($cid); |
||
| 163 | $contest_rule=$contestModel->rule($cid); |
||
| 164 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 165 | $pid=$contestModel->getPid($cid, $ncode); |
||
| 166 | if (empty($pid)) { |
||
| 167 | return Redirect::route('contest.board', ['cid' => $cid]); |
||
| 168 | } |
||
| 169 | $pcode=$problemModel->pcode($pid); |
||
| 170 | |||
| 171 | $prob_detail=$problemModel->detail($pcode, $cid); |
||
| 172 | if ($problemModel->isBlocked($prob_detail["pid"], $cid)) { |
||
| 173 | return abort('403'); |
||
| 174 | } |
||
| 175 | $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]); |
||
| 176 | $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid); |
||
| 177 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 178 | $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid); |
||
| 179 | $pref=$compiler_pref["pref"]; |
||
| 180 | $submit_code=$compiler_pref["code"]; |
||
| 181 | $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]); |
||
| 182 | |||
| 183 | if (empty($prob_status)) { |
||
| 184 | $prob_status=[ |
||
| 185 | "verdict"=>"NOT SUBMIT", |
||
| 186 | "color"=>"" |
||
| 187 | ]; |
||
| 188 | } |
||
| 189 | |||
| 190 | $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width'); |
||
| 191 | if(empty($editor_left_width)) $editor_left_width='40'; |
||
| 192 | |||
| 193 | return view('contest.board.editor', [ |
||
| 194 | 'page_title'=>"Problem Detail", |
||
| 195 | 'navigation' => "Contest", |
||
| 196 | 'site_title'=>$contest_name, |
||
| 197 | 'contest_name'=>$contest_name, |
||
| 198 | 'cid'=> $cid, |
||
| 199 | 'detail' => $prob_detail, |
||
| 200 | 'compiler_list' => $compiler_list, |
||
| 201 | 'status' => $prob_status, |
||
| 202 | 'pref' => $pref<0 ? 0 : $pref, |
||
| 203 | 'submit_code' => $submit_code, |
||
| 204 | 'contest_mode' => true, |
||
| 205 | 'contest_ended' => $contest_ended, |
||
| 206 | 'ncode' => $ncode, |
||
| 207 | 'contest_rule' => $contest_rule, |
||
| 208 | 'problem_set' => $problemSet, |
||
| 209 | 'clearance' => $clearance, |
||
| 210 | 'oj_detail' => $oj_detail, |
||
| 211 | 'editor_left_width'=>$editor_left_width, |
||
| 212 | ]); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Show the Contest Rank Page. |
||
| 217 | * |
||
| 218 | * @return Response |
||
| 219 | */ |
||
| 220 | public function rank($cid) |
||
| 249 | ]); |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Show the Contest Status Page. |
||
| 254 | * |
||
| 255 | * @return Response |
||
| 256 | */ |
||
| 257 | public function status($cid) |
||
| 282 | ]); |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Show the Contest Clarification Page. |
||
| 287 | * |
||
| 288 | * @return Response |
||
| 289 | */ |
||
| 290 | public function clarification($cid) |
||
| 291 | { |
||
| 292 | $contestModel=new ContestModel(); |
||
| 293 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 294 | if (!$clearance) { |
||
| 295 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 296 | } |
||
| 297 | $basicInfo=$contestModel->basic($cid); |
||
| 298 | $contest_name=$contestModel->contestName($cid); |
||
| 299 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 300 | $clarificationList=$contestModel->getClarificationList($cid); |
||
| 301 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 302 | return view('contest.board.clarification', [ |
||
| 303 | 'page_title'=>"Clarification", |
||
| 304 | 'navigation' => "Contest", |
||
| 305 | 'site_title'=>$contest_name, |
||
| 306 | 'contest_name'=>$contest_name, |
||
| 307 | 'cid'=>$cid, |
||
| 308 | 'custom_info' => $customInfo, |
||
| 309 | 'clarification_list' => $clarificationList, |
||
| 310 | 'contest_ended' => $contest_ended, |
||
| 311 | 'clearance'=> $clearance, |
||
| 312 | 'basic'=>$basicInfo, |
||
| 313 | ]); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Show the Contest Print Page. |
||
| 318 | * |
||
| 319 | * @return Response |
||
| 320 | */ |
||
| 321 | public function print($cid) |
||
| 322 | { |
||
| 323 | $contestModel=new ContestModel(); |
||
| 324 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 325 | if (!$clearance) { |
||
| 326 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 327 | } |
||
| 328 | $basicInfo=$contestModel->basic($cid); |
||
| 329 | $contest_name=$contestModel->contestName($cid); |
||
| 330 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 331 | return view('contest.board.print', [ |
||
| 332 | 'page_title'=>"Print", |
||
| 333 | 'navigation' => "Contest", |
||
| 334 | 'site_title'=>$contest_name, |
||
| 335 | 'contest_name'=>$contest_name, |
||
| 336 | 'cid'=>$cid, |
||
| 337 | 'custom_info' => $customInfo, |
||
| 338 | 'clearance'=> $clearance, |
||
| 339 | 'basic'=>$basicInfo, |
||
| 340 | ]); |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Show the Contest Admin Page. |
||
| 345 | * |
||
| 346 | * @return Response |
||
| 347 | */ |
||
| 348 | public function admin($cid) |
||
| 374 | ]); |
||
| 375 | } |
||
| 376 | |||
| 377 | public function downloadContestAccountXlsx($cid) |
||
| 378 | { |
||
| 379 | $contestModel=new ContestModel(); |
||
| 380 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 381 | if ($clearance <= 2) { |
||
| 382 | return Redirect::route('contest_detail', ['cid' => $cid]); |
||
| 383 | } |
||
| 384 | $account=$contestModel->getContestAccount($cid); |
||
| 385 | if($account==null){ |
||
| 386 | return ; |
||
| 387 | }else{ |
||
| 388 | $AccountExport=new AccountExport($account); |
||
| 389 | $filename="ContestAccount$cid"; |
||
| 390 | return Excel::download($AccountExport, $filename.'.xlsx'); |
||
| 391 | } |
||
| 392 | } |
||
| 393 | |||
| 394 | public function analysis($cid){ |
||
| 412 | ]); |
||
| 413 | } |
||
| 414 | |||
| 415 | public function refreshContestRank($cid){ |
||
| 425 | } |
||
| 426 | } |
||
| 427 |