| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 26 | public function testResolve() |
||
| 27 | { |
||
| 28 | parent::testResolve(); |
||
| 29 | |||
| 30 | $this |
||
| 31 | ->given( |
||
| 32 | $deferred = new Deferred(), |
||
| 33 | $onFulfilled = $this->delegateMockWithReturn($deferred->promise()), |
||
| 34 | /** @var \Cubiche\Core\Async\Promise\ThenResolver $resolver */ |
||
| 35 | $resolver = $this->newTestedInstance($onFulfilled), |
||
| 36 | $onFulfilledPromise = $this->delegateMock(), |
||
| 37 | $onNotifyPromise = $this->delegateMock() |
||
| 38 | ) |
||
| 39 | ->when(function () use ($resolver, $onFulfilledPromise, $onNotifyPromise) { |
||
| 40 | $resolver->resolve(); |
||
| 41 | $resolver->promise()->then($onFulfilledPromise, null, $onNotifyPromise); |
||
| 42 | }) |
||
| 43 | ->then() |
||
| 44 | ->delegateCall($onFulfilledPromise) |
||
| 45 | ->never() |
||
| 46 | ->delegateCall($onNotifyPromise) |
||
| 47 | ->never() |
||
| 48 | ; |
||
| 49 | |||
| 50 | $this |
||
| 51 | ->when($deferred->notify('state')) |
||
| 52 | ->then() |
||
| 53 | ->delegateCall($onNotifyPromise) |
||
| 54 | ->withArguments('state') |
||
| 55 | ->once() |
||
| 56 | ; |
||
| 57 | |||
| 58 | $this |
||
| 59 | ->when($deferred->resolve('foo')) |
||
| 60 | ->then() |
||
| 61 | ->delegateCall($onFulfilledPromise) |
||
| 62 | ->withArguments('foo') |
||
| 63 | ->once() |
||
| 64 | ; |
||
| 65 | |||
| 66 | $this |
||
| 67 | ->given( |
||
| 68 | $reason = new \Exception(), |
||
| 69 | $onFulfilled = $this->delegateMockWithReturn(new RejectedPromise($reason)), |
||
| 70 | /** @var \Cubiche\Core\Async\Promise\ThenResolver $resolver */ |
||
| 71 | $resolver = $this->newTestedInstance($onFulfilled), |
||
| 72 | $onRejectedPromise = $this->delegateMock() |
||
| 73 | ) |
||
| 74 | ->when(function () use ($resolver, $onRejectedPromise) { |
||
| 75 | $resolver->resolve(); |
||
| 76 | $resolver->promise()->then(null, $onRejectedPromise); |
||
| 77 | }) |
||
| 78 | ->then() |
||
| 79 | ->delegateCall($onRejectedPromise) |
||
| 80 | ->withArguments($reason) |
||
| 81 | ->once() |
||
| 82 | ; |
||
| 83 | } |
||
| 84 | |||
| 110 |