| Conditions | 10 |
| Paths | 3 |
| Total Lines | 38 |
| 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 |
||
| 106 | private function wait() |
||
| 107 | { |
||
| 108 | do { |
||
| 109 | if (empty($this->queries)) { |
||
| 110 | break; |
||
| 111 | } |
||
| 112 | $links = $errors = $reject = []; |
||
| 113 | foreach ($this->queries as $link) { |
||
| 114 | $links[] = $errors[] = $reject[] = $link['l']; |
||
| 115 | } |
||
| 116 | if (!mysqli_poll($links, $errors, $reject, self::$sleep, self::$usleep)) { |
||
| 117 | continue; |
||
| 118 | } |
||
| 119 | foreach ($this->queries as $l => $link) { |
||
| 120 | $promise = $this->getPromise($link); |
||
| 121 | $cnx = $this->getConnection($link); |
||
| 122 | try { |
||
| 123 | $result = $cnx->reap_async_query(); |
||
| 124 | if ($result instanceof mysqli_result) { |
||
| 125 | $promise->resolve($result); |
||
| 126 | } else { |
||
| 127 | $errNo = mysqli_errno($cnx); |
||
| 128 | $errStr = mysqli_error($cnx); |
||
| 129 | if (0 !== $errNo || 0 !== strlen($errStr)) { |
||
| 130 | throw new mysqli_sql_exception($errStr, $errNo); |
||
| 131 | } else { |
||
| 132 | $promise->resolve($cnx); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } catch (mysqli_sql_exception $e) { |
||
| 136 | $promise->reject($e); |
||
| 137 | } |
||
| 138 | $this->processed++; |
||
| 139 | unset($this->queries[$l]); |
||
| 140 | } |
||
| 141 | } while ($this->processed < count($this->queries)); |
||
| 142 | $this->reset(); |
||
| 143 | } |
||
| 144 | |||
| 153 |