| Conditions | 6 |
| Paths | 16 |
| Total Lines | 56 |
| Code Lines | 43 |
| 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 |
||
| 48 | private function codeForcesSubmit() |
||
| 49 | { |
||
| 50 | // $this->sub['language']=substr($this->post_data["lang"], 2, 50); |
||
| 51 | |||
| 52 | $submissionModel=new SubmissionModel(); |
||
| 53 | $s_num=$submissionModel->countSolution($this->post_data["solution"]); |
||
| 54 | $space=''; |
||
| 55 | for ($i=0; $i<$s_num; $i++) { |
||
| 56 | $space.=' '; |
||
| 57 | } |
||
| 58 | $contestId=$this->post_data["cid"]; |
||
|
|
|||
| 59 | $submittedProblemIndex=$this->post_data["iid"]; |
||
| 60 | $var=substr($this->post_data["lang"], 0, 2); |
||
| 61 | $programTypeId=$var; |
||
| 62 | if ($var[0]==0) { |
||
| 63 | $programTypeId=$var[1]; |
||
| 64 | } |
||
| 65 | $source=($space.chr(10).$this->post_data["solution"]); |
||
| 66 | |||
| 67 | |||
| 68 | $response=$this->grab_page("codeforces.com/contest/{$this->post_data['cid']}/submit", "codeforces", [], $this->selectedJudger["handle"]); |
||
| 69 | |||
| 70 | $exploded=explode("name='csrf_token' value='", $response); |
||
| 71 | $token=explode("'/>", $exploded[2])[0]; |
||
| 72 | |||
| 73 | $params=[ |
||
| 74 | 'csrf_token' => $token, |
||
| 75 | 'action' => 'submitSolutionFormSubmitted', |
||
| 76 | 'ftaa' => '', |
||
| 77 | 'bfaa' => '', |
||
| 78 | 'submittedProblemIndex' => $submittedProblemIndex, |
||
| 79 | 'programTypeId' => $programTypeId, |
||
| 80 | 'source' => $source, |
||
| 81 | 'tabSize' => 4, |
||
| 82 | 'sourceFile' => '', |
||
| 83 | ]; |
||
| 84 | $response=$this->post_data("codeforces.com/contest/{$this->post_data['cid']}/submit?csrf_token=".$token, http_build_query($params), "codeforces", true, true, true, false, [], $this->selectedJudger["handle"]); |
||
| 85 | $this->sub["jid"]=$this->selectedJudger["jid"]; |
||
| 86 | if (strpos($response, 'alert("Source code hasn\'t submitted because of warning, please read it.");') !== false) { |
||
| 87 | $this->sub['verdict']='Compile Error'; |
||
| 88 | preg_match('/<div class="roundbox " style="font-size:1.2rem;margin:0.5em 0;padding:0.5em;text-align:left;background-color:#eca;">[\s\S]*?<div class="roundbox-rb"> <\/div>([\s\S]*?)<div/', $response, $match); |
||
| 89 | $warning = str_replace('Press button to submit the solution.', '', $match[1]); |
||
| 90 | $this->sub['compile_info']=trim($warning); |
||
| 91 | } elseif (substr_count($response, 'My Submissions')!=2) { |
||
| 92 | file_put_contents(base_path('storage/logs/'.time().'.html'),$response); |
||
| 93 | // Forbidden? |
||
| 94 | $exploded=explode('<span class="error for__source">', $response); |
||
| 95 | if(!isset($exploded[1])){ |
||
| 96 | $this->sub['verdict']="Submission Error"; |
||
| 97 | }else{ |
||
| 98 | $this->sub['compile_info']=explode("</span>", $exploded[1])[0]; |
||
| 99 | $this->sub['verdict']="Submission Error"; |
||
| 100 | } |
||
| 101 | } else { |
||
| 102 | preg_match('/submissionId="(\d+)"/', $response, $match); |
||
| 103 | $this->sub['remote_id']=$match[1]; |
||
| 104 | } |
||
| 126 |