Conditions | 3 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 56 |
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 |
||
180 | public function testNonCompletedAck() |
||
181 | { |
||
182 | $payload = json_decode($this->payload, true); |
||
183 | $payload['job'] = new Job(1, 'demo'); |
||
184 | $btJob2 = Mockery::mock('\Pheanstalk\Job') |
||
185 | ->shouldReceive('getData') |
||
186 | ->andReturn(json_encode($payload)) |
||
187 | ->getMock(); |
||
188 | $btClient = Mockery::mock('\Pheanstalk\Pheanstalk') |
||
189 | ->shouldReceive('useTube') |
||
190 | ->with(Mockery::mustBe('mail_queue')) |
||
191 | ->andReturnSelf() |
||
192 | ->shouldReceive('put') |
||
193 | ->withAnyArgs() |
||
194 | ->andReturn(3) |
||
195 | ->shouldReceive('statsTube') |
||
196 | ->twice() |
||
197 | ->andReturnUsing( |
||
198 | function () { |
||
199 | static $f; |
||
200 | if($f === null){ |
||
201 | $f = true; |
||
202 | } |
||
203 | $f = !$f; |
||
204 | return $f |
||
205 | ? new ArrayResponse( |
||
206 | 'test', [ |
||
207 | 'current-jobs-delayed' => 0, |
||
208 | 'current-jobs-urgent' => 0, |
||
209 | 'current-jobs-ready' => 0 |
||
210 | ] |
||
211 | ) |
||
212 | : new ArrayResponse('test', ['current-jobs-delayed' => 1,]); |
||
213 | } |
||
214 | ) |
||
215 | ->shouldReceive('watchOnly') |
||
216 | ->with(Mockery::mustBe('mail_queue')) |
||
217 | ->andReturnSelf() |
||
218 | ->shouldReceive('reserve') |
||
219 | ->with(0) |
||
220 | ->andReturn($btJob2) |
||
221 | ->shouldReceive('release') |
||
222 | ->andReturn(1) |
||
223 | ->shouldReceive('delete') |
||
224 | ->andReturn(1) |
||
225 | ->getMock(); |
||
226 | |||
227 | $btConnection = Mockery::mock('\Da\Mailer\Queue\Backend\Beanstalk\BeanstalkdQueueStoreConnection') |
||
228 | ->shouldReceive('connect') |
||
229 | ->andReturnSelf() |
||
230 | ->shouldReceive('getInstance') |
||
231 | ->andReturn($btClient) |
||
232 | ->getMock(); |
||
233 | |||
234 | $btQueueStore = new BeanstalkdQueueStoreAdapter($btConnection); |
||
235 | |||
236 | |||
237 | $this->assertSame($btQueueStore, $btQueueStore->init()); |
||
238 | $this->assertTrue($btQueueStore->enqueue($this->mailJob) > 1); |
||
239 | |||
240 | $this->assertTrue($btQueueStore->isEmpty() === false); |
||
241 | |||
242 | $mailJob = $btQueueStore->dequeue(); |
||
243 | |||
244 | $this->assertTrue($btQueueStore->isEmpty() === true); |
||
245 | |||
246 | $this->assertTrue(!empty($mailJob->getMessage())); |
||
247 | |||
248 | $dequeuedMailMessage = MailMessage::fromArray(json_decode($mailJob->getMessage(), true)); |
||
249 | |||
250 | $this->assertEquals(FixtureHelper::getMailMessage(), $dequeuedMailMessage); |
||
251 | $btQueueStore->ack($mailJob); |
||
252 | } |
||
253 | } |
||
254 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: