Total Complexity | 42 |
Total Lines | 313 |
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 | return view('contest.board.challenge', [ |
||
54 | 'page_title'=>"Challenge", |
||
55 | 'navigation' => "Contest", |
||
56 | 'site_title'=>$contest_name, |
||
57 | 'cid'=>$cid, |
||
58 | 'contest_name'=>$contest_name, |
||
59 | 'contest_rule'=>$contest_rule, |
||
60 | 'problem_set'=> $problemSet, |
||
61 | 'remaining_time'=>$remainingTime, |
||
62 | 'custom_info' => $customInfo, |
||
63 | 'clarification_list' => $clarificationList, |
||
64 | 'clearance'=> $clearance, |
||
65 | 'basic'=>$basicInfo, |
||
66 | ]); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Show the Contest Editor Page. |
||
71 | * |
||
72 | * @return Response |
||
73 | */ |
||
74 | public function editor($cid, $ncode) |
||
75 | { |
||
76 | $contestModel=new ContestModel(); |
||
77 | $problemModel=new ProblemModel(); |
||
78 | $compilerModel=new CompilerModel(); |
||
79 | $submissionModel=new SubmissionModel(); |
||
80 | $accountModel=new AccountModel(); |
||
81 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
82 | $basicInfo=$contestModel->basic($cid); |
||
83 | if (!$clearance || time() < strtotime($basicInfo['begin_time'])) { |
||
84 | if($clearance == 3){ |
||
85 | return Redirect::route('contest.admin', ['cid' => $cid]); |
||
86 | }else{ |
||
87 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
88 | } |
||
89 | } |
||
90 | $contest_name=$contestModel->contestName($cid); |
||
91 | $contest_rule=$contestModel->rule($cid); |
||
92 | $contest_ended=$contestModel->isContestEnded($cid); |
||
93 | $pid=$contestModel->getPid($cid, $ncode); |
||
94 | if (empty($pid)) { |
||
95 | return Redirect::route('contest.board', ['cid' => $cid]); |
||
96 | } |
||
97 | $pcode=$problemModel->pcode($pid); |
||
98 | |||
99 | $prob_detail=$problemModel->detail($pcode, $cid); |
||
100 | if ($problemModel->isBlocked($prob_detail["pid"], $cid)) { |
||
101 | return abort('403'); |
||
102 | } |
||
103 | $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]); |
||
104 | $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid); |
||
105 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
106 | $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid); |
||
107 | $pref=$compiler_pref["pref"]; |
||
108 | $submit_code=$compiler_pref["code"]; |
||
109 | $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]); |
||
110 | |||
111 | if (empty($prob_status)) { |
||
112 | $prob_status=[ |
||
113 | "verdict"=>"NOT SUBMIT", |
||
114 | "color"=>"" |
||
115 | ]; |
||
116 | } |
||
117 | |||
118 | $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width'); |
||
119 | if(empty($editor_left_width)) $editor_left_width='40'; |
||
120 | |||
121 | return view('contest.board.editor', [ |
||
122 | 'page_title'=>"Problem Detail", |
||
123 | 'navigation' => "Contest", |
||
124 | 'site_title'=>$contest_name, |
||
125 | 'contest_name'=>$contest_name, |
||
126 | 'cid'=> $cid, |
||
127 | 'detail' => $prob_detail, |
||
128 | 'compiler_list' => $compiler_list, |
||
129 | 'status' => $prob_status, |
||
130 | 'pref' => $pref<0 ? 0 : $pref, |
||
131 | 'submit_code' => $submit_code, |
||
132 | 'contest_mode' => true, |
||
133 | 'contest_ended' => $contest_ended, |
||
134 | 'ncode' => $ncode, |
||
135 | 'contest_rule' => $contest_rule, |
||
136 | 'problem_set' => $problemSet, |
||
137 | 'clearance' => $clearance, |
||
138 | 'oj_detail' => $oj_detail, |
||
139 | 'editor_left_width'=>$editor_left_width, |
||
140 | ]); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Show the Contest Rank Page. |
||
145 | * |
||
146 | * @return Response |
||
147 | */ |
||
148 | public function rank($cid) |
||
149 | { |
||
150 | $contestModel=new ContestModel(); |
||
151 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
152 | $basicInfo=$contestModel->basic($cid); |
||
153 | if (!$clearance || time() < strtotime($basicInfo['begin_time'])) { |
||
154 | if($clearance == 3){ |
||
155 | return Redirect::route('contest.admin', ['cid' => $cid]); |
||
156 | }else{ |
||
157 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
158 | } |
||
159 | } |
||
160 | $contest_name=$contestModel->contestName($cid); |
||
161 | $contest_rule=$contestModel->contestRule($cid); |
||
162 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
163 | $customInfo=$contestModel->getCustomInfo($cid); |
||
164 | $contestRank=$contestModel->contestRank($cid, Auth::user()->id); |
||
165 | |||
166 | // To determine the ranking |
||
167 | foreach ($contestRank as $i => &$r) { |
||
168 | if($i != 0) { |
||
169 | if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){ |
||
170 | $r['rank'] = $contestRank[$i-1]['rank']; |
||
171 | }else{ |
||
172 | $r['rank'] = $i + 1; |
||
173 | } |
||
174 | }else{ |
||
175 | $r['rank'] = 1; |
||
176 | } |
||
177 | } |
||
178 | $rankFrozen=$contestModel->isFrozen($cid); |
||
179 | $frozenTime=$contestModel->frozenTime($cid); |
||
180 | return view('contest.board.rank', [ |
||
181 | 'page_title'=>"Rank", |
||
182 | 'navigation' => "Contest", |
||
183 | 'site_title'=>$contest_name, |
||
184 | 'contest_name'=>$contest_name, |
||
185 | 'contest_rule'=>$contest_rule, |
||
186 | 'cid'=>$cid, |
||
187 | 'problem_set'=>$problemSet, |
||
188 | 'custom_info' => $customInfo, |
||
189 | 'contest_rank' => $contestRank, |
||
190 | 'rank_frozen' => $rankFrozen, |
||
191 | 'frozen_time' => $frozenTime, |
||
192 | 'clearance'=> $clearance, |
||
193 | 'basic'=>$basicInfo, |
||
194 | ]); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Show the Contest Status Page. |
||
199 | * |
||
200 | * @return Response |
||
201 | */ |
||
202 | public function status(Request $request) |
||
237 | ]); |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Show the Contest Clarification Page. |
||
242 | * |
||
243 | * @return Response |
||
244 | */ |
||
245 | public function clarification($cid) |
||
272 | ]); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Show the Contest Print Page. |
||
277 | * |
||
278 | * @return Response |
||
279 | */ |
||
280 | public function print($cid) |
||
303 | ]); |
||
304 | } |
||
305 | |||
306 | public function analysis($cid){ |
||
331 |