Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 40 |
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 |
||
151 | public function testTimeout() |
||
152 | { |
||
153 | $this |
||
154 | ->given( |
||
155 | $loop = new Loop(), |
||
156 | $deferred = Promises::defer() |
||
157 | ) |
||
158 | ->when($timeout = Promises::timeout($deferred->promise(), 0.01, $loop)) |
||
159 | ->then() |
||
160 | ->object($timeout) |
||
161 | ->isInstanceOf(PromiseInterface::class) |
||
162 | ; |
||
163 | |||
164 | $this |
||
165 | ->given($onRejected = $this->delegateMock()) |
||
166 | ->when(function () use ($timeout, $onRejected, $loop) { |
||
167 | $timeout->otherwise($onRejected); |
||
168 | $loop->run(); |
||
169 | }) |
||
170 | ->then() |
||
171 | ->delegateCall($onRejected) |
||
172 | ->once() |
||
173 | ; |
||
174 | |||
175 | $this |
||
176 | ->given( |
||
177 | $onFulfilled = $this->delegateMock(), |
||
178 | $timeout = Promises::timeout(Promises::fulfilled('foo'), 0.01, $loop) |
||
179 | ) |
||
180 | ->when(function () use ($timeout, $onFulfilled, $loop) { |
||
181 | $timeout->then($onFulfilled); |
||
182 | $loop->run(); |
||
183 | }) |
||
184 | ->then() |
||
185 | ->delegateCall($onFulfilled) |
||
186 | ->withArguments('foo') |
||
187 | ->once() |
||
188 | ; |
||
189 | |||
190 | $this |
||
191 | ->given( |
||
192 | $reason = new \Exception(), |
||
193 | $onRejected = $this->delegateMock(), |
||
194 | $timeout = Promises::timeout(Promises::rejected($reason), 0.01, $loop) |
||
195 | ) |
||
196 | ->when(function () use ($timeout, $onRejected, $loop) { |
||
197 | $timeout->otherwise($onRejected); |
||
198 | $loop->run(); |
||
199 | }) |
||
200 | ->then() |
||
201 | ->delegateCall($onRejected) |
||
202 | ->withArguments($reason) |
||
203 | ->once() |
||
204 | ; |
||
205 | } |
||
206 | |||
242 |