| Conditions | 13 |
| Paths | 216 |
| Total Lines | 47 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 58 | public function sendRequest( |
||
| 59 | $url, |
||
| 60 | $method = 'GET', |
||
| 61 | $querydata = null, |
||
| 62 | $headers = null, |
||
| 63 | $options = null |
||
| 64 | ) { |
||
| 65 | if (null === $headers) { |
||
| 66 | $headers = array(); |
||
| 67 | } elseif (!is_array($headers)) { |
||
| 68 | $headers = (array) $headers; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (null === $options) { |
||
| 72 | $options = array(); |
||
| 73 | } elseif (!is_array($options)) { |
||
| 74 | $options = (array) $options; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (!array_key_exists('timeout', $options)) { |
||
| 78 | $options['timeout'] = $this->timeout; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($method == self::PUT && !array_key_exists('Content-Length', $headers)) { |
||
| 82 | if (empty($querydata)) { |
||
| 83 | $headers['Content-Length'] = 0; |
||
| 84 | } else { |
||
| 85 | $headers['Content-Length'] = is_string($querydata) |
||
| 86 | ? strlen($querydata) |
||
| 87 | : strlen(http_build_query($querydata)); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $response = parent::sendRequest($url, $method, $querydata, $headers, $options); |
||
| 92 | |||
| 93 | if (array_key_exists('error_msg', $response) && (null !== $response['error_msg'])) { |
||
| 94 | throw new Exceptions\Error(substr($response['error_msg'], 0, strpos($response['error_msg'], ';'))); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($response['status'] >= 400) { |
||
| 98 | throw new Exceptions\ResponseError($response['status']); |
||
| 99 | } |
||
| 100 | |||
| 101 | $response['headers'] = new Client\Headers($response['headers']); |
||
|
|
|||
| 102 | |||
| 103 | return $response; |
||
| 104 | } |
||
| 105 | |||
| 142 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: