Conditions | 5 |
Paths | 16 |
Total Lines | 52 |
Code Lines | 37 |
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 |
||
29 | public function makeRequest($url, $method, $values, $token = null) |
||
30 | { |
||
31 | list($postFields, $getFields) = $this->processValues($values); |
||
32 | |||
33 | if (count($getFields)) { |
||
34 | $url = $url . '?' . implode('&', $getFields); |
||
35 | } |
||
36 | |||
37 | $startTime = microtime(); |
||
38 | |||
39 | $curl = curl_init(); |
||
40 | curl_setopt($curl, CURLOPT_URL, $url); |
||
41 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); |
||
42 | curl_setopt($curl, CURLOPT_NOBODY, false); |
||
43 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
||
44 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
45 | curl_setopt($curl, CURLOPT_VERBOSE, false); |
||
46 | curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
||
47 | if (count($postFields)) { |
||
48 | curl_setopt($curl, CURLOPT_POST, 1); |
||
49 | curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $postFields)); |
||
50 | } |
||
51 | |||
52 | curl_setopt($curl, CURLOPT_TIMEOUT, 30); |
||
53 | $headers = []; |
||
54 | if ($token) { |
||
|
|||
55 | $headers = ['Authorization: Bearer ' . $token]; |
||
56 | curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
||
57 | } |
||
58 | |||
59 | $consoleResponse = new ConsoleResponse( |
||
60 | $url, |
||
61 | $method, |
||
62 | $postFields, |
||
63 | $getFields, |
||
64 | $headers |
||
65 | ); |
||
66 | |||
67 | $responseBody = curl_exec($curl); |
||
68 | $elapsed = intval((microtime() - $startTime) * 1000); |
||
69 | |||
70 | $curlErrorNumber = curl_errno($curl); |
||
71 | $curlError = curl_error($curl); |
||
72 | if ($curlErrorNumber > 0) { |
||
73 | $consoleResponse->logError($curlErrorNumber, $curlError, $elapsed); |
||
74 | } else { |
||
75 | $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
||
76 | $consoleResponse->logRequest($httpCode, $responseBody, $elapsed); |
||
77 | } |
||
78 | |||
79 | return $consoleResponse; |
||
80 | } |
||
81 | |||
134 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: