| Conditions | 16 |
| Paths | 228 |
| Total Lines | 80 |
| 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 |
||
| 86 | public function push(): array |
||
| 87 | { |
||
| 88 | if (!$this->curlMultiHandle) { |
||
| 89 | $this->curlMultiHandle = curl_multi_init(); |
||
|
|
|||
| 90 | |||
| 91 | if (!defined('CURLPIPE_MULTIPLEX')) { |
||
| 92 | define('CURLPIPE_MULTIPLEX', 2); |
||
| 93 | } |
||
| 94 | |||
| 95 | curl_multi_setopt($this->curlMultiHandle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); |
||
| 96 | curl_multi_setopt($this->curlMultiHandle, CURLMOPT_MAX_HOST_CONNECTIONS, $this->maxConcurrentConnections); |
||
| 97 | } |
||
| 98 | |||
| 99 | $mh = $this->curlMultiHandle; |
||
| 100 | |||
| 101 | $i = 0; |
||
| 102 | while (!empty($this->notifications) && $i++ < $this->nbConcurrentRequests) { |
||
| 103 | $notification = array_pop($this->notifications); |
||
| 104 | curl_multi_add_handle($mh, $this->prepareHandle($notification)); |
||
| 105 | } |
||
| 106 | |||
| 107 | // Clear out curl handle buffer |
||
| 108 | do { |
||
| 109 | $execrun = curl_multi_exec($mh, $running); |
||
| 110 | } while ($execrun === CURLM_CALL_MULTI_PERFORM); |
||
| 111 | |||
| 112 | // Continue processing while we have active curl handles |
||
| 113 | while ($running > 0 && $execrun === CURLM_OK) { |
||
| 114 | // Block until data is available |
||
| 115 | $select_fd = curl_multi_select($mh); |
||
| 116 | // If select returns -1 while running, wait 250 microseconds before continuing |
||
| 117 | // Using curl_multi_timeout would be better but it isn't available in PHP yet |
||
| 118 | // https://php.net/manual/en/function.curl-multi-select.php#115381 |
||
| 119 | if ($running && $select_fd === -1) { |
||
| 120 | usleep(250); |
||
| 121 | } |
||
| 122 | |||
| 123 | // Continue to wait for more data if needed |
||
| 124 | do { |
||
| 125 | $execrun = curl_multi_exec($mh, $running); |
||
| 126 | } while ($execrun === CURLM_CALL_MULTI_PERFORM); |
||
| 127 | |||
| 128 | // Start reading results |
||
| 129 | while ($done = curl_multi_info_read($mh)) { |
||
| 130 | $handle = $done['handle']; |
||
| 131 | |||
| 132 | $result = curl_multi_getcontent($handle); |
||
| 133 | |||
| 134 | // find out which token the response is about |
||
| 135 | $token = curl_getinfo($handle, CURLINFO_PRIVATE); |
||
| 136 | |||
| 137 | $responseParts = explode("\r\n\r\n", $result, 2); |
||
| 138 | $headers = ''; |
||
| 139 | $body = ''; |
||
| 140 | if (isset($responseParts[0])) { |
||
| 141 | $headers = $responseParts[0]; |
||
| 142 | } |
||
| 143 | if (isset($responseParts[1])) { |
||
| 144 | $body = $responseParts[1]; |
||
| 145 | } |
||
| 146 | |||
| 147 | $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
||
| 148 | $responseCollection[] = new Response($statusCode, $headers, $body, $token); |
||
| 149 | curl_multi_remove_handle($mh, $handle); |
||
| 150 | curl_close($handle); |
||
| 151 | |||
| 152 | if (!empty($this->notifications)) { |
||
| 153 | $notification = array_pop($this->notifications); |
||
| 154 | curl_multi_add_handle($mh, $this->prepareHandle($notification)); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($this->autoCloseConnections) { |
||
| 160 | curl_multi_close($mh); |
||
| 161 | $this->curlMultiHandle = null; |
||
| 162 | } |
||
| 163 | |||
| 164 | return $responseCollection; |
||
| 165 | } |
||
| 166 | |||
| 267 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..