| Conditions | 53 |
| Paths | 2026 |
| Total Lines | 371 |
| Code Lines | 249 |
| 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 |
||
| 15 | public function __construct() |
||
| 16 | { |
||
| 17 | $this->MODEL=new SubmissionModel(); |
||
| 18 | $ret=[]; |
||
| 19 | |||
| 20 | $uva_v=[ |
||
| 21 | 10=>'Submission Error', |
||
| 22 | 15=>'Submission Error', // Can't be judged |
||
| 23 | // 20 In queue |
||
| 24 | 30=>"Compile Error", |
||
| 25 | 35=>"Compile Error", // Restricted function |
||
| 26 | 40=>"Runtime Error", |
||
| 27 | 45=>"Output Limit Exceeded", |
||
| 28 | 50=>"Time Limit Exceed", |
||
| 29 | 60=>"Memory Limit Exceed", |
||
| 30 | 70=>"Wrong Answer", |
||
| 31 | 80=>"Presentation Error", |
||
| 32 | 90=>"Accepted", |
||
| 33 | ]; |
||
| 34 | |||
| 35 | $codeforces_v=[ |
||
| 36 | "COMPILATION_ERROR"=>"Compile Error", |
||
| 37 | "RUNTIME_ERROR"=> "Runtime Error", |
||
| 38 | "WRONG_ANSWER"=> "Wrong Answer", |
||
| 39 | "TIME_LIMIT_EXCEEDED"=>"Time Limit Exceed", |
||
| 40 | "OK"=>"Accepted", |
||
| 41 | "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed", |
||
| 42 | "PRESENTATION_ERROR"=>"Presentation Error", |
||
| 43 | "IDLENESS_LIMIT_EXCEEDED"=>"Idleness Limit Exceed" |
||
| 44 | ]; |
||
| 45 | |||
| 46 | $spoj_v=[ |
||
| 47 | "compilation error"=>"Compile Error", |
||
| 48 | "runtime error"=> "Runtime Error", |
||
| 49 | "wrong answer"=> "Wrong Answer", |
||
| 50 | "time limit exceeded"=>"Time Limit Exceed", |
||
| 51 | "accepted"=>"Accepted" |
||
| 52 | ]; |
||
| 53 | |||
| 54 | $contesthunter_v=[ |
||
| 55 | '正确'=>"Accepted", |
||
| 56 | '答案错误'=>"Wrong Answer", |
||
| 57 | '超出时间限制'=>"Time Limit Exceed", |
||
| 58 | '运行时错误'=>"Runtime Error", |
||
| 59 | "超出内存限制"=>"Memory Limit Exceed", |
||
| 60 | '比较器错误'=>'Submission Error', |
||
| 61 | '超出输出限制'=>"Output Limit Exceeded", |
||
| 62 | '编译错误'=>"Compile Error", |
||
| 63 | ]; |
||
| 64 | |||
| 65 | $poj_v=[ |
||
| 66 | 'Accepted'=>"Accepted", |
||
| 67 | "Presentation Error"=>"Presentation Error", |
||
| 68 | 'Time Limit Exceeded'=>"Time Limit Exceed", |
||
| 69 | "Memory Limit Exceeded"=>"Memory Limit Exceed", |
||
| 70 | 'Wrong Answer'=>"Wrong Answer", |
||
| 71 | 'Runtime Error'=>"Runtime Error", |
||
| 72 | 'Output Limit Exceeded'=>"Output Limit Exceeded", |
||
| 73 | 'Compile Error'=>"Compile Error", |
||
| 74 | ]; |
||
| 75 | |||
| 76 | $vijos_v=[ |
||
| 77 | 'Accepted'=>"Accepted", |
||
| 78 | 'Wrong Answer'=>"Wrong Answer", |
||
| 79 | 'Time Exceeded'=>"Time Limit Exceed", |
||
| 80 | "Memory Exceeded"=>"Memory Limit Exceed", |
||
| 81 | 'Runtime Error'=>"Runtime Error", |
||
| 82 | 'Compile Error'=>"Compile Error", |
||
| 83 | 'System Error'=>"Submission Error", |
||
| 84 | 'Canceled'=>"Submission Error", |
||
| 85 | 'Unknown Error'=>"Submission Error", |
||
| 86 | 'Ignored'=>"Submission Error", |
||
| 87 | ]; |
||
| 88 | |||
| 89 | $pta_v=[ |
||
| 90 | 'ACCEPTED'=>"Accepted", |
||
| 91 | 'COMPILE_ERROR'=>"Compile Error", |
||
| 92 | 'FLOAT_POINT_EXCEPTION'=>"Runtime Error", |
||
| 93 | 'INTERNAL_ERROR'=>"Submission Error", |
||
| 94 | "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed", |
||
| 95 | 'MULTIPLE_ERROR'=>"Runtime Error", |
||
| 96 | 'NON_ZERO_EXIT_CODE'=>"Runtime Error", |
||
| 97 | 'NO_ANSWER'=>"Compile Error", |
||
| 98 | 'OUTPUT_LIMIT_EXCEEDED'=>"Output Limit Exceeded", |
||
| 99 | 'OVERRIDDEN'=>"Submission Error", |
||
| 100 | 'PARTIAL_ACCEPTED'=>"Partially Accepted", |
||
| 101 | "PRESENTATION_ERROR"=>"Presentation Error", |
||
| 102 | 'RUNTIME_ERROR'=>"Runtime Error", |
||
| 103 | 'SAMPLE_ERROR'=>"Wrong Answer", |
||
| 104 | 'SEGMENTATION_FAULT'=>"Runtime Error", |
||
| 105 | 'SKIPPED'=>"Submission Error", |
||
| 106 | 'TIME_LIMIT_EXCEEDED'=>"Time Limit Exceed", |
||
| 107 | 'WRONG_ANSWER'=>"Wrong Answer", |
||
| 108 | ]; |
||
| 109 | |||
| 110 | $result=$this->MODEL->getWaitingSubmission(); |
||
| 111 | $judger=new JudgerModel(); |
||
| 112 | $contestModel=new ContestModel(); |
||
| 113 | $curl=new Curl(); |
||
| 114 | |||
| 115 | $cfList=$this->get_last_codeforces($this->MODEL->countEarliestWaitingSubmission(2)+100); |
||
| 116 | $uvaList=$this->get_last_uva($this->MODEL->getEarliestSubmission(7)); |
||
| 117 | $poj=[]; |
||
| 118 | |||
| 119 | $pojJudgerList=$judger->list(4); |
||
| 120 | $pojJudgerName=urlencode($pojJudgerList[0]["handle"]); |
||
| 121 | if ($this->MODEL->countWaitingSubmission(5)) { |
||
| 122 | $this->appendPOJStatus($poj, $pojJudgerName); |
||
| 123 | } |
||
| 124 | // $uva=$this->get_last_uva($this->MODEL->countWaitingSubmission('Uva')); |
||
| 125 | // $uval=$this->get_last_uvalive($this->MODEL->countWaitingSubmission('UvaLive')); |
||
| 126 | // $sj=$this->get_last_spoj($this->MODEL->countWaitingSubmission('Spoj')); |
||
| 127 | |||
| 128 | $i=0; |
||
| 129 | $j=0; |
||
| 130 | $k=0; |
||
| 131 | $l=0; |
||
| 132 | foreach ($result as $row) { |
||
| 133 | if ($row['oid']==2) { |
||
| 134 | $cf=[]; |
||
| 135 | foreach ($cfList as $c) { |
||
| 136 | if ($c[3]==$row["remote_id"]) { |
||
| 137 | $cf=$c; |
||
| 138 | break; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | if (empty($cf)) { |
||
| 142 | |||
| 143 | // $this->MODEL->updateSubmission($row['sid'], ['verdict'=>"Submission Error"]); |
||
| 144 | } else { |
||
| 145 | if (isset($codeforces_v[$cf[2]])) { |
||
| 146 | $sub=[]; |
||
| 147 | $sub['verdict']=$codeforces_v[$cf[2]]; |
||
| 148 | if ($sub['verdict']=='Compile Error') { |
||
| 149 | if (!isset($cfCSRF)) { |
||
| 150 | $cfCSRF=[]; |
||
| 151 | } |
||
| 152 | $handle=$judger->detail($row['jid'])['handle']; |
||
| 153 | if (!isset($cfCSRF[$handle])) { |
||
| 154 | $res=$curl->grab_page('http://codeforces.com', 'codeforces', [], $handle); |
||
| 155 | preg_match('/<meta name="X-Csrf-Token" content="([0-9a-z]*)"/', $res, $match); |
||
| 156 | $cfCSRF[$handle]=$match[1]; |
||
| 157 | } |
||
| 158 | $res=$curl->post_data('http://codeforces.com/data/judgeProtocol', ['submissionId'=>$row['remote_id'], 'csrf_token'=>$cfCSRF[$handle]], 'codeforces', true, false, false, false, [], $handle); |
||
| 159 | $sub['compile_info']=json_decode($res); |
||
| 160 | } |
||
| 161 | $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
||
| 162 | $sub['time']=$cf[0]; |
||
| 163 | $sub['memory']=$cf[1]; |
||
| 164 | $sub['remote_id']=$cf[3]; |
||
| 165 | |||
| 166 | $ret[$row['sid']]=[ |
||
| 167 | "verdict"=>$sub['verdict'] |
||
| 168 | ]; |
||
| 169 | |||
| 170 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | // if (isset($codeforces_v[$cf[$i][2]])) { |
||
| 175 | // $sub['verdict']=$codeforces_v[$cf[$i][2]]; |
||
| 176 | // $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
||
| 177 | // $sub['time']=$cf[$i][0]; |
||
| 178 | // $sub['memory']=$cf[$i][1]; |
||
| 179 | // $sub['remote_id']=$cf[$i][3]; |
||
| 180 | |||
| 181 | // $ret[$row['sid']]=[ |
||
| 182 | // "verdict"=>$sub['verdict'] |
||
| 183 | // ]; |
||
| 184 | |||
| 185 | // $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 186 | // } |
||
| 187 | // $i++; |
||
| 188 | } elseif ($row['oid']==3) { |
||
| 189 | try { |
||
| 190 | $sub=[]; |
||
| 191 | $res=Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
||
| 192 | preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match); |
||
| 193 | $status=$match[1]; |
||
| 194 | if (!array_key_exists($status, $contesthunter_v)) { |
||
| 195 | continue; |
||
| 196 | } |
||
| 197 | $sub['verdict']=$contesthunter_v[$status]; |
||
| 198 | $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
||
| 199 | $sub['remote_id']=$row['remote_id']; |
||
| 200 | if ($sub['verdict']!="Submission Error" && $sub['verdict']!="Compile Error") { |
||
| 201 | preg_match('/占用内存[\s\S]*?(\d+).*?KiB/m', $res->body, $match); |
||
| 202 | $sub['memory']=$match[1]; |
||
| 203 | $maxtime=0; |
||
| 204 | preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches); |
||
| 205 | foreach ($matches[1] as $time) { |
||
| 206 | if ($time<$maxtime) { |
||
| 207 | $maxtime=$time; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | $sub['time']=$maxtime; |
||
| 211 | } else { |
||
| 212 | $sub['memory']=0; |
||
| 213 | $sub['time']=0; |
||
| 214 | if ($sub['verdict']=='Compile Error') { |
||
| 215 | preg_match('/<h2>结果 <small>各个测试点的详细结果<\/small><\/h2>\s*<pre>([\s\S]*?)<\/pre>/', $res->body, $match); |
||
| 216 | $sub['compile_info']=html_entity_decode($match[1], ENT_QUOTES); |
||
| 217 | } |
||
| 218 | } |
||
| 219 | |||
| 220 | $ret[$row['sid']]=[ |
||
| 221 | "verdict"=>$sub['verdict'] |
||
| 222 | ]; |
||
| 223 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 224 | } catch (Exception $e) { |
||
| 225 | } |
||
| 226 | } elseif ($row['oid']==4) { |
||
| 227 | $sub=[]; |
||
| 228 | if (!isset($poj[$row['remote_id']])) { |
||
| 229 | $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']); |
||
| 230 | if (!isset($poj[$row['remote_id']])) { |
||
| 231 | continue; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | $status=$poj[$row['remote_id']]; |
||
| 235 | $sub['verdict']=$poj_v[$status['verdict']]; |
||
| 236 | if ($sub['verdict']=='Compile Error') { |
||
| 237 | try { |
||
| 238 | $res=Requests::get('http://poj.org/showcompileinfo?solution_id='.$row['remote_id']); |
||
| 239 | preg_match('/<pre>([\s\S]*)<\/pre>/', $res->body, $match); |
||
| 240 | $sub['compile_info']=html_entity_decode($match[1], ENT_QUOTES); |
||
| 241 | } catch (Exception $e) {} |
||
| 242 | } |
||
| 243 | $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
||
| 244 | $sub['time']=$status['time']; |
||
| 245 | $sub['memory']=$status['memory']; |
||
| 246 | $sub['remote_id']=$row['remote_id']; |
||
| 247 | |||
| 248 | $ret[$row['sid']]=[ |
||
| 249 | "verdict"=>$sub['verdict'] |
||
| 250 | ]; |
||
| 251 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 252 | } elseif ($row['oid']==5) { |
||
| 253 | try { |
||
| 254 | $sub=[]; |
||
| 255 | $res=Requests::get('https://vijos.org/records/'.$row['remote_id']); |
||
| 256 | preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match); |
||
| 257 | $status=$match[1]; |
||
| 258 | if (!array_key_exists($status, $vijos_v)) { |
||
| 259 | continue; |
||
| 260 | } |
||
| 261 | if ($match[1]=='Compile Error') { |
||
| 262 | preg_match('/<pre class="compiler-text">([\s\S]*?)<\/pre>/', $res->body, $match); |
||
| 263 | $sub['compile_info']=html_entity_decode($match[1], ENT_QUOTES); |
||
| 264 | } |
||
| 265 | $sub['verdict']=$vijos_v[$status]; |
||
| 266 | preg_match('/<dt>分数<\/dt>\s*<dd>(\d+)<\/dd>/', $res->body, $match); |
||
| 267 | $isOI=$row['cid'] && $contestModel->rule($row['cid'])==2; |
||
| 268 | if ($isOI) { |
||
| 269 | $sub['score']=$match[1]; |
||
| 270 | if ($sub['verdict']=="Wrong Answer" && $sub['score']!=0) { |
||
| 271 | $sub['verdict']='Partially Accepted'; |
||
| 272 | } |
||
| 273 | } else { |
||
| 274 | $sub['score']=$match[1]==100 ? 100 : 0; |
||
| 275 | } |
||
| 276 | $sub['remote_id']=$row['remote_id']; |
||
| 277 | if ($sub['verdict']!="Submission Error" && $sub['verdict']!="Compile Error") { |
||
| 278 | $maxtime=0; |
||
| 279 | preg_match_all('/<td class="col--time">(?:≥)?(\d+)ms<\/td>/', $res->body, $matches); |
||
| 280 | foreach ($matches as $match) { |
||
| 281 | if ($match[1]>$maxtime) { |
||
| 282 | $maxtime=$match[1]; |
||
| 283 | } |
||
| 284 | } |
||
| 285 | $sub['time']=$maxtime; |
||
| 286 | preg_match('/<dt>峰值内存<\/dt>\s*<dd>(?:≥)?([\d.]+) ([KM])iB<\/dd>/', $res->body, $match); |
||
| 287 | $memory=$match[1]; |
||
| 288 | if ($match[2]=='M') { |
||
| 289 | $memory*=1024; |
||
| 290 | } |
||
| 291 | $sub['memory']=intval($memory); |
||
| 292 | } else { |
||
| 293 | $sub['memory']=0; |
||
| 294 | $sub['time']=0; |
||
| 295 | } |
||
| 296 | |||
| 297 | $ret[$row['sid']]=[ |
||
| 298 | "verdict"=>$sub['verdict'] |
||
| 299 | ]; |
||
| 300 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 301 | } catch (Exception $e) { |
||
| 302 | } |
||
| 303 | } elseif ($row['oid']==6) { |
||
| 304 | try { |
||
| 305 | $sub=[]; |
||
| 306 | $response=$curl->grab_page("https://pintia.cn/api/submissions/".$row['remote_id'], 'pta', ['Accept: application/json;charset=UTF-8']); |
||
| 307 | $data=json_decode($response, true); |
||
| 308 | if (!isset($pta_v[$data['submission']['status']])) { |
||
| 309 | continue; |
||
| 310 | } |
||
| 311 | $sub['verdict']=$pta_v[$data['submission']['status']]; |
||
| 312 | if ($data['submission']['status']=='COMPILE_ERROR') { |
||
| 313 | $sub['compile_info']=$data['submission']['judgeResponseContents'][0]['programmingJudgeResponseContent']['compilationResult']['log']; |
||
| 314 | } |
||
| 315 | $isOI=$row['cid'] && $contestModel->rule($row['cid'])==2; |
||
| 316 | $sub['score']=$data['submission']['score']; |
||
| 317 | if (!$isOI) { |
||
| 318 | if ($sub['verdict']=="Partially Accepted") { |
||
| 319 | $sub['verdict']='Wrong Answer'; |
||
| 320 | $sub['score']=0; |
||
| 321 | } |
||
| 322 | } |
||
| 323 | $sub['remote_id']=$row['remote_id']; |
||
| 324 | $sub['memory']=$data['submission']['memory'] / 1024; |
||
| 325 | $sub['time']=$data['submission']['time'] * 1000; |
||
| 326 | |||
| 327 | $ret[$row['sid']]=[ |
||
| 328 | "verdict"=>$sub['verdict'] |
||
| 329 | ]; |
||
| 330 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 331 | } catch (Exception $e) { |
||
| 332 | } |
||
| 333 | } elseif ($row['oid']==7) { |
||
| 334 | if (array_key_exists($row['remote_id'], $uvaList)) { |
||
| 335 | $sub=[]; |
||
| 336 | $sub['verdict']=$uva_v[$uvaList[$row['remote_id']]['verdict']]; |
||
| 337 | if ($sub['verdict']==='Compile Error') { |
||
| 338 | $response=$this->grab_page("https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9&page=show_compilationerror&submission=$row[remote_id]", 'uva', [], $uvaList['handle']); |
||
| 339 | if (preg_match('/<pre>([\s\S]*)<\/pre>/', $response, $match)) $sub['compile_info']=trim($match[1]); |
||
| 340 | } |
||
| 341 | $sub['score']=$sub['verdict']=="Accepted" ? 1 : 0; |
||
| 342 | $sub['remote_id']=$row['remote_id']; |
||
| 343 | $sub['time']=$uvaList[$row['remote_id']]['time']; |
||
| 344 | |||
| 345 | $ret[$row['sid']]=[ |
||
| 346 | "verdict"=>$sub['verdict'] |
||
| 347 | ]; |
||
| 348 | $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 349 | } |
||
| 350 | } |
||
| 351 | // if ($row['oid']=='Spoj') { |
||
| 352 | // if (isset($spoj_v[$sj[$j][2]])) { |
||
| 353 | // $sub['verdict']=$spoj_v[$sj[$j][2]]; |
||
| 354 | // $sub['time']=$sj[$j][0]; |
||
| 355 | // $sub['memory']=$sj[$j][1]; |
||
| 356 | // $v=$sub['verdict']; |
||
| 357 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 358 | // $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 359 | // } |
||
| 360 | // $j++; |
||
| 361 | // } |
||
| 362 | // if ($row['oid']=='Uva') { |
||
| 363 | // if (isset($uva_v[$uva[$k][2]])) { |
||
| 364 | // $sub['verdict']=$uva_v[$uva[$k][2]]; |
||
| 365 | // $sub['time']=$uva[$k][0]; |
||
| 366 | // $sub['memory']=$uva[$k][1]; |
||
| 367 | // $v=$sub['verdict']; |
||
| 368 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 369 | // $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 370 | // } |
||
| 371 | // $k++; |
||
| 372 | // } |
||
| 373 | // if ($row['oid']=='UvaLive') { |
||
| 374 | // if (isset($uva_v[$uval[$l][2]])) { |
||
| 375 | // $sub['verdict']=$uva_v[$uval[$l][2]]; |
||
| 376 | // $sub['time']=$uval[$l][0]; |
||
| 377 | // $sub['memory']=$uval[$l][1]; |
||
| 378 | // $v=$sub['verdict']; |
||
| 379 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 380 | // $this->MODEL->updateSubmission($row['sid'], $sub); |
||
| 381 | // } |
||
| 382 | // $l++; |
||
| 383 | // } |
||
| 384 | } |
||
| 385 | $this->ret=$ret; |
||
| 386 | } |
||
| 576 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: