| Conditions | 14 | 
| Paths | 771 | 
| Total Lines | 44 | 
| Code Lines | 36 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 89 | public function post_data($all_data) | ||
| 90 |     { | ||
| 91 |         if (isset($all_data["site"]))         $site=$all_data["site"]; else throw new Exception("site is not exist in all_data"); | ||
| 92 |         if (isset($all_data["data"]))         $data=$all_data["data"]; else throw new Exception("data is not exist in all_data"); | ||
| 93 |         if (isset($all_data["oj"]))           $oj=$all_data["oj"]; else throw new Exception("oj is not exist in all_data"); | ||
| 94 | if (isset($all_data["ret"])) $ret=$all_data["ret"]; else $ret=false; | ||
| 95 | if (isset($all_data["follow"])) $follow=$all_data["follow"]; else $follow=true; | ||
| 96 | if (isset($all_data["returnHeader"])) $returnHeader=$all_data["returnHeader"]; else $returnHeader=true; | ||
| 97 | if (isset($all_data["postJson"])) $postJson=$all_data["postJson"]; else $postJson=false; | ||
| 98 | if (isset($all_data["extraHeaders"])) $extraHeaders=$all_data["extraHeaders"]; else $extraHeaders=[]; | ||
| 99 | if (isset($all_data["handle"])) $handle=$all_data["handle"]; else $handle="default"; | ||
| 100 | if (isset($all_data["vcid"])) $vcid=$all_data["vcid"]."_"; else $vcid=""; | ||
| 101 | |||
| 102 | $handle=urlencode($handle); | ||
| 103 | |||
| 104 | $datapost=curl_init(); | ||
| 105 |         $headers=array("Expect:"); | ||
| 106 |         if ($postJson) { | ||
| 107 |             $data=$data ? json_encode($data) : '{}'; | ||
| 108 | array_push($headers, 'Content-Type: application/json', 'Content-Length: '.strlen($data)); | ||
| 109 | } | ||
| 110 |         curl_setopt($datapost, CURLOPT_CAINFO, babel_path("Cookies/cacert.pem")); | ||
| 111 | curl_setopt($datapost, CURLOPT_URL, $site); | ||
| 112 | curl_setopt($datapost, CURLOPT_HEADER, $returnHeader); | ||
| 113 | curl_setopt($datapost, CURLOPT_HTTPHEADER, array_merge($headers, $extraHeaders)); | ||
| 114 | curl_setopt($datapost, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"); | ||
| 115 | curl_setopt($datapost, CURLOPT_POST, true); | ||
| 116 | |||
| 117 | curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); | ||
| 118 | curl_setopt($datapost, CURLOPT_SSL_VERIFYPEER, false); | ||
| 119 | curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, $follow); | ||
| 120 | |||
| 121 | curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); | ||
| 122 |         curl_setopt($datapost, CURLOPT_COOKIEFILE, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie")); | ||
| 123 |         curl_setopt($datapost, CURLOPT_COOKIEJAR, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie")); | ||
| 124 | ob_start(); | ||
| 125 | $response=curl_exec($datapost); | ||
| 126 |         if (curl_errno($datapost)) { | ||
| 127 | throw new Exception(curl_error($datapost), 10000); | ||
| 128 | } | ||
| 129 | ob_end_clean(); | ||
| 130 | curl_close($datapost); | ||
| 131 | unset($datapost); | ||
| 132 | return $response; | ||
| 133 | } | ||
| 135 |