Conditions | 11 |
Paths | 40 |
Total Lines | 56 |
Code Lines | 28 |
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 |
||
39 | public function call($service, $payload, $callback_endpoint = '') { |
||
40 | |||
41 | $service_endpoint = $this->sandcage_api_endpoint_base; |
||
42 | |||
43 | if ($service == 'scheduleTasks') { |
||
44 | $service_endpoint .= 'schedule-tasks'; |
||
45 | } else if ($service == 'destroyFiles') { |
||
46 | $service_endpoint .= 'destroy-files'; |
||
47 | } else if ($service == 'getInfo') { |
||
48 | $service_endpoint .= 'get-info'; |
||
49 | } else if ($service == 'listFiles') { |
||
50 | $service_endpoint .= 'list-files'; |
||
51 | } |
||
52 | |||
53 | $this->post_fields = array('key'=>$this->sandcage_api_key) + $payload; |
||
54 | |||
55 | if ((($service == 'scheduleTasks') || ($service == 'destroyFiles')) && ($callback_endpoint != '')) { |
||
56 | $this->post_fields['callback_url'] = $callback_endpoint; |
||
57 | } |
||
58 | |||
59 | // Initialize the cURL session |
||
60 | $ch = curl_init($service_endpoint); |
||
61 | |||
62 | curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); |
||
63 | |||
64 | // Handle open_basedir & safe mode |
||
65 | if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
||
66 | $this->follow_location = true; |
||
67 | } |
||
68 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location); |
||
69 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); |
||
70 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||
71 | curl_setopt($ch, CURLOPT_POST, TRUE); |
||
72 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->post_fields)); |
||
73 | |||
74 | // Execute the cURL session |
||
75 | $this->response = curl_exec($ch); |
||
76 | |||
77 | // Retry if certificates are missing. |
||
78 | if (curl_errno($ch) == CURLE_SSL_CACERT) { |
||
79 | |||
80 | // Set the pem file holding the CA Root Certificates to verify the peer with. |
||
81 | curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); |
||
82 | |||
83 | // Retry execution after setting CURLOPT_CAINFO |
||
84 | $this->response = curl_exec($ch); |
||
85 | |||
86 | } |
||
87 | |||
88 | // Get information regarding the transfer |
||
89 | $this->status = curl_getinfo($ch); |
||
90 | |||
91 | // Close the cURL session |
||
92 | curl_close($ch); |
||
93 | |||
94 | } |
||
95 | |||
116 |