Conditions | 10 |
Paths | 33 |
Total Lines | 80 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
39 | public function run() |
||
40 | { |
||
41 | $judgerModel=new JudgerModel(); |
||
42 | $compilerModel=new CompilerModel(); |
||
43 | $problemModel=new ProblemModel(); |
||
44 | $language=$compilerModel->detail($this->coid)['lcode']; |
||
45 | $bestServer=$judgerModel->server($this->oid); |
||
46 | if (is_null($bestServer)) { |
||
47 | $this->verdict=[ |
||
48 | "verdict"=>"Compile Error", |
||
49 | "compile_info"=>"No Available Judger.", |
||
50 | "data"=>[] |
||
51 | ]; |
||
52 | return; |
||
53 | } |
||
54 | $probBasic=$problemModel->basic($this->pid); |
||
55 | $submitURL="http://".$bestServer["host"].":".$bestServer["port"]; |
||
56 | $submit_data=[ |
||
57 | "solution" => $this->solution, |
||
58 | "language" => $language, |
||
59 | "max_cpu_time" => $probBasic["time_limit"] * ($language=="java" ? 3 : 1), |
||
60 | "max_memory" => $probBasic["memory_limit"] * 1024, |
||
61 | "test_case_id" => $probBasic["pcode"], |
||
62 | "token" => $bestServer["token"], |
||
63 | "spj_version" => null, |
||
64 | "spj_config" => null, |
||
65 | "spj_compile_config" => null, |
||
66 | "spj_src" => null |
||
67 | ]; |
||
68 | if ($probBasic["spj"] && $probBasic["spj_version"]) { |
||
69 | $submit_data["spj_version"]=$probBasic["spj_version"]; |
||
70 | $submit_data["spj_config"]=$probBasic["spj_lang"]; |
||
71 | $submit_data["spj_compile_config"]=[ |
||
72 | "src_name" => "spj-{spj_version}.c", |
||
73 | "exe_name" => "spj-{spj_version}", |
||
74 | "max_cpu_time" => 3000, |
||
75 | "max_real_time" => 5000, |
||
76 | "max_memory" => 1073741824, |
||
77 | "compile_command" => "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}" |
||
78 | ]; // fixed at C99, future linked with spj_lang |
||
79 | $submit_data["spj_src"]=$probBasic["spj_src"]; |
||
80 | } |
||
81 | $judgeClient=new JudgeClient($submit_data["token"], $submitURL); |
||
82 | $temp=$judgeClient->judge($submit_data["solution"], $submit_data["language"], $submit_data["test_case_id"], [ |
||
83 | 'output' => false, |
||
84 | 'max_cpu_time'=>$submit_data['max_cpu_time'], |
||
85 | 'max_memory'=>$submit_data['max_memory'], |
||
86 | 'spj_version'=>$submit_data['spj_version'], |
||
87 | 'spj_config'=>$submit_data['spj_config'], |
||
88 | 'spj_compile_config'=>$submit_data['spj_compile_config'], |
||
89 | 'spj_src'=>$submit_data['spj_src'] |
||
90 | ]); |
||
91 | if (!is_null($temp["err"])) { |
||
92 | if (strpos($temp["data"], 'Compiler runtime error, info: ')!==false) { |
||
93 | $tempRes=json_decode(explode('Compiler runtime error, info: ', $temp["data"])[1], true); |
||
94 | $this->verdict['verdict']=$this->verdictDict[$tempRes["result"]]; |
||
95 | $this->verdict['compile_info']=null; |
||
96 | } else { |
||
97 | $this->verdict['verdict']=$this->verdictDict["-2"]; |
||
98 | $this->verdict['compile_info']=$temp["data"]; |
||
99 | } |
||
100 | $this->verdict['data']=[]; |
||
101 | return $this->verdict; |
||
102 | } |
||
103 | |||
104 | $this->verdict['verdict']="Accepted"; |
||
105 | foreach ($temp["data"] as $record) { |
||
106 | if ($record["result"]) { |
||
107 | // well... WA or anyway |
||
108 | $this->verdict['verdict']=$this->verdictDict[$record["result"]]; |
||
109 | break; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | $this->verdict['data']=$temp["data"]; |
||
114 | $this->verdict['compile_info']=null; |
||
115 | foreach ($this->verdict['data'] as &$record) { |
||
116 | $record["result"]=$this->verdictDict[$record["result"]]; |
||
117 | } |
||
118 | return $this->verdict; |
||
119 | } |
||
121 |