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 |
||
122 | protected function makeRequest($http_verb, $api_method, $args = [], $timeout = 10, $url = null) : Response |
||
123 | { |
||
124 | if ($url === null) { |
||
125 | $url = $this->api_endpoint . '/' . $this->accountID . '/' . $api_method; |
||
126 | } |
||
127 | |||
128 | if (function_exists('curl_init') && function_exists('curl_setopt')) { |
||
129 | |||
130 | $ch = curl_init(); |
||
131 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
132 | curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
||
133 | 'Accept: application/vnd.api+json', |
||
134 | 'Content-Type: application/vnd.api+json', |
||
135 | ]); |
||
136 | curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/Drip (github.com/drewm/drip)'); |
||
137 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
||
138 | curl_setopt($ch, CURLOPT_USERPWD, $this->token . ': '); |
||
139 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); |
||
140 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
||
141 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
||
142 | curl_setopt($ch, CURLOPT_URL, $url); |
||
143 | |||
144 | switch ($http_verb) { |
||
145 | case 'post': |
||
146 | curl_setopt($ch, CURLOPT_POST, 1); |
||
147 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); |
||
148 | break; |
||
149 | |||
150 | case 'get': |
||
151 | $query = http_build_query($args); |
||
152 | curl_setopt($ch, CURLOPT_URL, $url . '?' . $query); |
||
153 | break; |
||
154 | |||
155 | case 'delete': |
||
156 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
||
157 | break; |
||
158 | } |
||
159 | |||
160 | $result = curl_exec($ch); |
||
161 | |||
162 | if (!curl_errno($ch)) { |
||
163 | $info = curl_getinfo($ch); |
||
164 | curl_close($ch); |
||
165 | return new Response($info, $result); |
||
166 | } |
||
167 | |||
168 | $errno = curl_errno($ch); |
||
169 | $error = curl_error($ch); |
||
170 | |||
171 | curl_close($ch); |
||
172 | |||
173 | throw new DripException($error, $errno); |
||
174 | } else { |
||
175 | throw new DripException("cURL support is required, but can't be found.", 1); |
||
176 | } |
||
177 | } |
||
178 | |||
230 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.