| Total Complexity | 58 |
| Total Lines | 341 |
| Duplicated Lines | 0 % |
| Changes | 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) |
||
| 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 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 84 | $basicInfo=$contestModel->basic($cid); |
||
| 85 | if (!$clearance || time()<strtotime($basicInfo['begin_time'])) { |
||
| 86 | if ($clearance==3) { |
||
| 87 | return Redirect::route('contest.board.admin', ['cid' => $cid]); |
||
| 88 | } else { |
||
| 89 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | $basicInfo=$contestModel->basic($cid); |
||
| 93 | if ($basicInfo['public'] && !$basicInfo['audit_status']) { |
||
| 94 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 95 | } |
||
| 96 | $contest_name=$contestModel->contestName($cid); |
||
| 97 | $contest_rule=$contestModel->rule($cid); |
||
| 98 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 99 | $pid=$contestModel->getPid($cid, $ncode); |
||
| 100 | if (empty($pid)) { |
||
| 101 | return Redirect::route('contest.board.index', ['cid' => $cid]); |
||
| 102 | } |
||
| 103 | $pcode=$problemModel->pcode($pid); |
||
| 104 | |||
| 105 | $prob_detail=$problemModel->detail($pcode, $cid); |
||
| 106 | if ($problemModel->isBlocked($prob_detail["pid"], $cid)) { |
||
| 107 | return abort('403'); |
||
| 108 | } |
||
| 109 | $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]); |
||
| 110 | $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid); |
||
| 111 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 112 | $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid); |
||
| 113 | $pref=$compiler_pref["pref"]; |
||
| 114 | $submit_code=$compiler_pref["code"]; |
||
| 115 | $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]); |
||
| 116 | |||
| 117 | if (empty($prob_status)) { |
||
| 118 | $prob_status=[ |
||
| 119 | "verdict"=>"NOT SUBMIT", |
||
| 120 | "color"=>"" |
||
| 121 | ]; |
||
| 122 | } |
||
| 123 | |||
| 124 | $accountExt=Auth::user()->getExtra(['editor_left_width', 'editor_theme']); |
||
| 125 | $editor_left_width=isset($accountExt['editor_left_width']) ? $accountExt['editor_left_width'] : '40'; |
||
| 126 | $editor_theme=isset($accountExt['editor_theme']) ? $accountExt['editor_theme'] : config('app.editor_theme'); |
||
| 127 | $themeConfig=MonacoTheme::getTheme($editor_theme); |
||
| 128 | |||
| 129 | return view('contest.board.editor', [ |
||
| 130 | 'page_title'=>"Problem Detail", |
||
| 131 | 'navigation' => "Contest", |
||
| 132 | 'site_title'=>$contest_name, |
||
| 133 | 'contest_name'=>$contest_name, |
||
| 134 | 'cid'=> $cid, |
||
| 135 | 'detail' => $prob_detail, |
||
| 136 | 'compiler_list' => $compiler_list, |
||
| 137 | 'status' => $prob_status, |
||
| 138 | 'pref' => $pref<0 ? 0 : $pref, |
||
| 139 | 'submit_code' => $submit_code, |
||
| 140 | 'contest_mode' => true, |
||
| 141 | 'contest_ended' => $contest_ended, |
||
| 142 | 'ncode' => $ncode, |
||
| 143 | 'contest_rule' => $contest_rule, |
||
| 144 | 'problem_set' => $problemSet, |
||
| 145 | 'clearance' => $clearance, |
||
| 146 | 'oj_detail' => $oj_detail, |
||
| 147 | 'editor_left_width'=>$editor_left_width, |
||
| 148 | 'theme_config'=>$themeConfig, |
||
| 149 | 'editor_themes'=>MonacoTheme::getAll(), |
||
| 150 | ]); |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Show the Contest Rank Page. |
||
| 155 | * |
||
| 156 | * @return Response |
||
| 157 | */ |
||
| 158 | public function rank($cid) |
||
| 159 | { |
||
| 160 | $contestModel=new ContestModel(); |
||
| 161 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 162 | $basicInfo=$contestModel->basic($cid); |
||
| 163 | if (!$clearance || time()<strtotime($basicInfo['begin_time'])) { |
||
| 164 | if ($clearance==3) { |
||
| 165 | return Redirect::route('contest.board.admin', ['cid' => $cid]); |
||
| 166 | } else { |
||
| 167 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | $basicInfo=$contestModel->basic($cid); |
||
| 171 | if ($basicInfo['public'] && !$basicInfo['audit_status']) { |
||
| 172 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 173 | } |
||
| 174 | $contest_name=$contestModel->contestName($cid); |
||
| 175 | $contest_rule=$contestModel->contestRule($cid); |
||
| 176 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 177 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 178 | $contestRank=$contestModel->contestRank($cid, Auth::user()->id); |
||
| 179 | |||
| 180 | // To determine the ranking |
||
| 181 | foreach ($contestRank as $i => &$r) { |
||
| 182 | if ($i!=0) { |
||
| 183 | if ($r['score']==$contestRank[$i-1]['score'] && ($contest_rule==1 ? ($r['penalty']==$contestRank[$i-1]['penalty']) : 1)) { |
||
| 184 | $r['rank']=$contestRank[$i-1]['rank']; |
||
| 185 | } else { |
||
| 186 | $r['rank']=$i+1; |
||
| 187 | } |
||
| 188 | } else { |
||
| 189 | $r['rank']=1; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | $rankFrozen=$contestModel->isFrozen($cid); |
||
| 193 | $frozenTime=$contestModel->frozenTime($cid); |
||
| 194 | return view('contest.board.rank', [ |
||
| 195 | 'page_title'=>"Rank", |
||
| 196 | 'navigation' => "Contest", |
||
| 197 | 'site_title'=>$contest_name, |
||
| 198 | 'contest_name'=>$contest_name, |
||
| 199 | 'contest_rule'=>$contest_rule, |
||
| 200 | 'cid'=>$cid, |
||
| 201 | 'problem_set'=>$problemSet, |
||
| 202 | 'custom_info' => $customInfo, |
||
| 203 | 'contest_rank' => $contestRank, |
||
| 204 | 'rank_frozen' => $rankFrozen, |
||
| 205 | 'frozen_time' => $frozenTime, |
||
| 206 | 'clearance'=> $clearance, |
||
| 207 | 'basic'=>$basicInfo, |
||
| 208 | ]); |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Show the Contest Status Page. |
||
| 213 | * |
||
| 214 | * @return Response |
||
| 215 | */ |
||
| 216 | public function status(Request $request) |
||
| 255 | ]); |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Show the Contest Clarification Page. |
||
| 260 | * |
||
| 261 | * @return Response |
||
| 262 | */ |
||
| 263 | public function clarification($cid) |
||
| 293 | ]); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Show the Contest Print Page. |
||
| 298 | * |
||
| 299 | * @return Response |
||
| 300 | */ |
||
| 301 | public function print($cid) |
||
| 327 | ]); |
||
| 328 | } |
||
| 329 | |||
| 330 | public function analysis($cid) { |
||
| 359 |