Conditions | 8 |
Paths | 18 |
Total Lines | 56 |
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 |
||
100 | protected function makeRequest($http_verb, $api_method, $args = [], $timeout = 10, $url = null) : Response |
||
101 | { |
||
102 | if ($url === null) { |
||
103 | $url = $this->api_endpoint . '/' . $this->accountID . '/' . $api_method; |
||
104 | } |
||
105 | |||
106 | if (function_exists('curl_init') && function_exists('curl_setopt')) { |
||
107 | |||
108 | $ch = curl_init(); |
||
109 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
110 | curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
||
111 | 'Accept: application/vnd.api+json', |
||
112 | 'Content-Type: application/vnd.api+json', |
||
113 | ]); |
||
114 | curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/Drip (github.com/drewm/drip)'); |
||
115 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
||
116 | curl_setopt($ch, CURLOPT_USERPWD, $this->token . ': '); |
||
117 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); |
||
118 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
||
119 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
||
120 | curl_setopt($ch, CURLOPT_URL, $url); |
||
121 | |||
122 | switch ($http_verb) { |
||
123 | case 'post': |
||
124 | curl_setopt($ch, CURLOPT_POST, 1); |
||
125 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); |
||
126 | break; |
||
127 | |||
128 | case 'get': |
||
129 | $query = http_build_query($args); |
||
130 | curl_setopt($ch, CURLOPT_URL, $url . '?' . $query); |
||
131 | break; |
||
132 | |||
133 | case 'delete': |
||
134 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
||
135 | break; |
||
136 | } |
||
137 | |||
138 | $result = curl_exec($ch); |
||
139 | |||
140 | if (!curl_errno($ch)) { |
||
141 | $info = curl_getinfo($ch); |
||
142 | curl_close($ch); |
||
143 | return new Response($info, $result); |
||
144 | } |
||
145 | |||
146 | $errno = curl_errno($ch); |
||
147 | $error = curl_error($ch); |
||
148 | |||
149 | curl_close($ch); |
||
150 | |||
151 | throw new DripException($error, $errno); |
||
152 | } else { |
||
153 | throw new DripException("cURL support is required, but can't be found.", 1); |
||
154 | } |
||
155 | } |
||
156 | |||
208 |