Conditions | 13 |
Paths | 387 |
Total Lines | 40 |
Code Lines | 33 |
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 |
||
75 | protected function post_data($all_data) |
||
76 | { |
||
77 | if(isset($all_data["site"])) $site = $all_data["site"]; else throw new Exception("site is not exist in all_data"); |
||
78 | if(isset($all_data["data"])) $data = $all_data["data"]; else throw new Exception("data is not exist in all_data"); |
||
79 | if(isset($all_data["oj"])) $oj = $all_data["oj"]; else throw new Exception("oj is not exist in all_data"); |
||
80 | if(isset($all_data["ret"])) $ret = $all_data["ret"]; else $ret = false; |
||
81 | if(isset($all_data["follow"])) $follow = $all_data["follow"]; else $follow = true; |
||
82 | if(isset($all_data["returnHeader"])) $returnHeader = $all_data["returnHeader"]; else $returnHeader = true; |
||
83 | if(isset($all_data["postJson"])) $postJson = $all_data["postJson"]; else $postJson = false; |
||
84 | if(isset($all_data["extraHeaders"])) $extraHeaders = $all_data["extraHeaders"]; else $extraHeaders = []; |
||
85 | if(isset($all_data["handle"])) $handle = $all_data["handle"]; else $handle = "default"; |
||
86 | |||
87 | $datapost=curl_init(); |
||
88 | $headers=array("Expect:"); |
||
89 | if ($postJson) { |
||
90 | $data=$data ? json_encode($data) : '{}'; |
||
91 | array_push($headers, 'Content-Type: application/json', 'Content-Length: '.strlen($data)); |
||
92 | } |
||
93 | curl_setopt($datapost, CURLOPT_CAINFO, dirname(__FILE__)."/../Cookies/cacert.pem"); |
||
94 | curl_setopt($datapost, CURLOPT_URL, $site); |
||
95 | curl_setopt($datapost, CURLOPT_HEADER, $returnHeader); |
||
96 | curl_setopt($datapost, CURLOPT_HTTPHEADER, array_merge($headers, $extraHeaders)); |
||
97 | 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"); |
||
98 | curl_setopt($datapost, CURLOPT_POST, true); |
||
99 | |||
100 | curl_setopt($datapost, CURLOPT_RETURNTRANSFER, $ret); |
||
101 | curl_setopt($datapost, CURLOPT_FOLLOWLOCATION, $follow); |
||
102 | |||
103 | curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); |
||
104 | curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
||
105 | curl_setopt($datapost, CURLOPT_COOKIEJAR, dirname(__FILE__)."/../Cookies/{$oj}_{$handle}.cookie"); |
||
106 | ob_start(); |
||
107 | $response=curl_exec($datapost); |
||
108 | if (curl_errno($datapost)) { |
||
109 | die(curl_error($datapost)); |
||
110 | } |
||
111 | ob_end_clean(); |
||
112 | curl_close($datapost); |
||
113 | unset($datapost); |
||
114 | return $response; |
||
115 | } |
||
117 |