| Conditions | 21 |
| Paths | 182 |
| Total Lines | 122 |
| Code Lines | 96 |
| 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 |
||
| 47 | public function submit() |
||
| 48 | { |
||
| 49 | $validator=Validator::make($this->post_data, [ |
||
| 50 | 'pid' => 'required|integer', |
||
| 51 | 'coid' => 'required|integer', |
||
| 52 | 'solution' => 'required', |
||
| 53 | ]); |
||
| 54 | if ($validator->fails()) { |
||
| 55 | $this->sub['verdict']="System Error"; |
||
| 56 | return; |
||
| 57 | } |
||
| 58 | $judgerModel=new JudgerModel(); |
||
| 59 | $problemModel=new ProblemModel(); |
||
| 60 | $contestModel=new ContestModel(); |
||
| 61 | $bestServer=$judgerModel->server($this->oid); |
||
| 62 | if (is_null($bestServer)) { |
||
| 63 | $this->sub['verdict']="Compile Error"; |
||
| 64 | $this->sub['compile_info']="No Available Judger."; |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | $probBasic=$problemModel->basic($this->post_data["pid"]); |
||
| 68 | $submitURL="http://".$bestServer["host"].":".$bestServer["port"]; |
||
| 69 | $submit_data=[ |
||
| 70 | "solution" => $this->post_data["solution"], |
||
| 71 | "language" => $this->post_data["lang"], |
||
| 72 | "max_cpu_time" => $probBasic["time_limit"] * ($this->post_data["lang"]=="java" ? 3 : 1), |
||
| 73 | "max_memory" => $probBasic["memory_limit"] * 1024, |
||
| 74 | "test_case_id" => $probBasic["pcode"], |
||
| 75 | "token" => $bestServer["token"], |
||
| 76 | "spj_version" => null, |
||
| 77 | "spj_config" => null |
||
| 78 | ]; |
||
| 79 | if($probBasic["spj"] && $probBasic["spj_version"]){ |
||
| 80 | $submit_data["spj_version"]=$probBasic["spj_version"]; |
||
| 81 | $submit_data["spj_config"]=$probBasic["spj_lang"]; |
||
| 82 | } |
||
| 83 | $temp=$this->submitJudger($submitURL, $submit_data); |
||
| 84 | if (isset($this->post_data["contest"])) { |
||
| 85 | $this->sub['cid']=$this->post_data["contest"]; |
||
| 86 | if ($contestModel->rule($this->sub['cid'])==2) { |
||
| 87 | // OI Mode |
||
| 88 | $this->sub['verdict']="Accepted"; |
||
| 89 | if (!is_null($temp["err"])) { |
||
| 90 | if (strpos($temp["data"], 'Compiler runtime error, info: ')!==false) { |
||
| 91 | $tempRes=json_decode(explode('Compiler runtime error, info: ', $temp["data"])[1], true); |
||
| 92 | $this->sub['verdict']=$this->verdictDict[$tempRes["result"]]; |
||
| 93 | $this->sub['time']=$tempRes["cpu_time"]; |
||
| 94 | $this->sub['memory']=round($tempRes["memory"] / 1024); |
||
| 95 | } else { |
||
| 96 | $this->sub['verdict']="Compile Error"; |
||
| 97 | $this->sub['time']=0; |
||
| 98 | $this->sub['memory']=0; |
||
| 99 | } |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | $this->sub["score"]=count($temp["data"]); |
||
| 103 | foreach ($temp["data"] as $record) { |
||
| 104 | if ($record["result"]) { |
||
| 105 | // well... WA or anyway |
||
| 106 | $this->sub['verdict']=$this->verdictDict[8]; |
||
| 107 | $this->sub["score"]--; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | if ($this->sub["score"]==0) { |
||
| 111 | $this->sub['verdict']=$this->verdictDict[$temp["data"][0]["result"]]; |
||
| 112 | $this->sub['time']=$temp["data"][0]["cpu_time"]; |
||
| 113 | $this->sub['memory']=round($temp["data"][0]["memory"] / 1024); |
||
| 114 | return; |
||
| 115 | } |
||
| 116 | $tempMemory=$temp["data"][0]["memory"]; |
||
| 117 | $tempTime=$temp["data"][0]["cpu_time"]; |
||
| 118 | foreach ($temp["data"] as $t) { |
||
| 119 | $tempMemory=max($tempMemory, $t["memory"]); |
||
| 120 | $tempTime=max($tempTime, $t["cpu_time"]); |
||
| 121 | } |
||
| 122 | $this->sub['time']=$tempTime; |
||
| 123 | $this->sub['memory']=round($tempMemory / 1024); |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $this->sub['cid']=null; |
||
| 128 | } |
||
| 129 | if (!is_null($temp["err"])) { |
||
| 130 | if (strpos($temp["data"], 'Compiler runtime error, info: ')!==false) { |
||
| 131 | $tempRes=json_decode(explode('Compiler runtime error, info: ', $temp["data"])[1], true); |
||
| 132 | $this->sub['verdict']=$this->verdictDict[$tempRes["result"]]; |
||
| 133 | $this->sub['time']=$tempRes["cpu_time"]; |
||
| 134 | $this->sub['memory']=round($tempRes["memory"] / 1024); |
||
| 135 | } else { |
||
| 136 | $this->sub['verdict']=$this->verdictDict["-2"]; |
||
| 137 | $this->sub['time']=0; |
||
| 138 | $this->sub['memory']=0; |
||
| 139 | $this->sub['compile_info']=$temp["data"]; |
||
| 140 | } |
||
| 141 | return; |
||
| 142 | } |
||
| 143 | $this->sub["score"]=count($temp["data"]); |
||
| 144 | foreach ($temp["data"] as $record) { |
||
| 145 | if ($record["result"]) { |
||
| 146 | // well... WA or anyway |
||
| 147 | $this->sub["score"]--; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | foreach ($temp["data"] as $record) { |
||
| 151 | if ($record["result"]) { |
||
| 152 | // well... WA or anyway |
||
| 153 | $this->sub['verdict']=$this->verdictDict[$record["result"]]; |
||
| 154 | $this->sub['time']=$record["cpu_time"]; |
||
| 155 | $this->sub['memory']=round($record["memory"] / 1024); |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | $tempMemory=$temp["data"][0]["memory"]; |
||
| 160 | $tempTime=$temp["data"][0]["cpu_time"]; |
||
| 161 | foreach ($temp["data"] as $t) { |
||
| 162 | $tempMemory=max($tempMemory, $t["memory"]); |
||
| 163 | $tempTime=max($tempTime, $t["cpu_time"]); |
||
| 164 | } |
||
| 165 | $this->sub['verdict']="Accepted"; |
||
| 166 | $this->sub['score']=1; |
||
| 167 | $this->sub['time']=$tempTime; |
||
| 168 | $this->sub['memory']=round($tempMemory / 1024); |
||
| 169 | } |
||
| 171 |