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