| Conditions | 11 |
| Paths | 108 |
| Total Lines | 40 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 27 |
| CRAP Score | 11.0055 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 163 | 13 | private function consumeCurlsAndUntils() |
|
| 164 | 13 | { |
|
| 165 | 13 | $entries = []; |
|
| 166 | // First, we have to poll completed entries |
||
| 167 | // DO NOT call curl_multi_add_handle() until polling done |
||
| 168 | 13 | while ($entry = curl_multi_info_read($this->mh)) { |
|
| 169 | 6 | $entries[] = $entry; |
|
| 170 | } |
||
| 171 | // Remove entry from multi handle to consume queue if available |
||
| 172 | 13 | foreach ($entries as $entry) { |
|
| 173 | 6 | curl_multi_remove_handle($this->mh, $entry['handle']); |
|
| 174 | 6 | unset($this->added[(string)$entry['handle']]); |
|
| 175 | 6 | if (!$this->queue) { |
|
|
1 ignored issue
–
show
|
|||
| 176 | 6 | continue; |
|
| 177 | } |
||
| 178 | 1 | $this->addOrEnqueue(array_shift($this->queue)); |
|
| 179 | } |
||
| 180 | // Now we check specified delay time elapsed |
||
| 181 | 13 | foreach ($this->untils as $id => $until) { |
|
| 182 | 3 | $diff = $until - microtime(true); |
|
| 183 | 3 | if ($diff > 0.0 || !isset($this->deferreds[$id])) { |
|
| 184 | 3 | continue; |
|
| 185 | } |
||
| 186 | 2 | $deferred = $this->deferreds[$id]; |
|
| 187 | 2 | unset($this->deferreds[$id], $this->untils[$id]); |
|
| 188 | 2 | $deferred->resolve(null); |
|
| 189 | } |
||
| 190 | // Finally, resolve cURL responses |
||
| 191 | 13 | foreach ($entries as $entry) { |
|
| 192 | 6 | if (!isset($this->deferreds[(string)$entry['handle']])) { |
|
| 193 | continue; |
||
| 194 | } |
||
| 195 | 6 | $r = $entry['result'] === CURLE_OK |
|
| 196 | 6 | ? curl_multi_getcontent($entry['handle']) |
|
| 197 | 6 | : new CURLException(curl_error($entry['handle']), $entry['result'], $entry['handle']); |
|
| 198 | 6 | $deferred = $this->deferreds[(string)$entry['handle']]; |
|
| 199 | 6 | unset($this->deferreds[(string)$entry['handle']]); |
|
| 200 | 6 | $r instanceof CURLException ? $deferred->reject($r) : $deferred->resolve($r); |
|
| 201 | } |
||
| 202 | 13 | } |
|
| 203 | } |
||
| 204 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.