Conditions | 14 |
Paths | 21 |
Total Lines | 47 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
189 | private function settle(int $state = null, array $args = []) : Promised |
||
190 | { |
||
191 | if (is_null($state)) { |
||
192 | $result = $this->result; |
||
193 | } else { |
||
194 | if ($this->ack) { |
||
195 | throw new InvalidState('Promise is already confirmed'); |
||
196 | } |
||
197 | $this->ack = true; |
||
198 | $this->state = $state; |
||
199 | $this->result = $result = $args; |
||
200 | } |
||
201 | |||
202 | $resolved = $this->state === self::FULFILLED; |
||
203 | |||
204 | /** |
||
205 | * @var Promised $next |
||
206 | */ |
||
207 | |||
208 | while (!$this->stack->isEmpty()) { |
||
209 | list($onFulfilled, $onRejected, $next) = $this->stack->shift(); |
||
210 | |||
211 | if (null === $executor = $resolved ? $onFulfilled : $onRejected) { |
||
212 | $resolved ? $next->resolve(...$result) : $next->reject(...$result); |
||
213 | continue; |
||
214 | } |
||
215 | |||
216 | list($stash, $failure) = $this->calling($executor, $next, $result); |
||
217 | |||
218 | if ($failure) { |
||
219 | if ($this->fusion || !$next->chained()) { |
||
220 | throw $failure; |
||
221 | } |
||
222 | } elseif ($stash instanceof Promised) { |
||
223 | if ($stash === $this) { |
||
224 | throw new TypeError('Response promise is same with current'); |
||
225 | } else { |
||
226 | $stash->then($this->resolver($next, self::FULFILLED), $this->resolver($next, self::REJECTED)); |
||
227 | } |
||
228 | } elseif ($stash instanceof Closure) { |
||
229 | $this->calling($stash, $next, [$next]); |
||
230 | } else { |
||
231 | $resolved ? $next->resolve($stash) : $next->reject($stash); |
||
232 | } |
||
233 | } |
||
234 | |||
235 | return $this; |
||
236 | } |
||
238 |