| Conditions | 7 |
| Paths | 2 |
| Total Lines | 54 |
| 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 |
||
| 49 | public function testService( |
||
| 50 | $method, |
||
| 51 | $parameters, |
||
| 52 | $return, |
||
| 53 | $emitNr, |
||
| 54 | $signalClass = '', |
||
| 55 | array $signalAttr = null |
||
| 56 | ) { |
||
| 57 | $innerService = $this->getServiceMock(); |
||
| 58 | $innerService->expects($this->once()) |
||
| 59 | ->method($method) |
||
| 60 | ->will( |
||
| 61 | $this->returnValueMap( |
||
| 62 | array( |
||
| 63 | array_merge($parameters, array($return)), |
||
| 64 | ) |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | |||
| 68 | $dispatcher = $this->createMock(SignalDispatcher::class); |
||
| 69 | $that = $this; |
||
| 70 | $d = $dispatcher->expects($this->exactly($emitNr)) |
||
| 71 | ->method('emit'); |
||
| 72 | if ($emitNr && $signalClass && $signalAttr) { |
||
| 73 | $d->with( |
||
| 74 | $this->callback( |
||
| 75 | function ($signal) use ($that, $signalClass, $signalAttr) { |
||
| 76 | if (!$signal instanceof $signalClass) { |
||
| 77 | $that->fail( |
||
| 78 | "The signal is not an instance of $signalClass" |
||
| 79 | ); |
||
| 80 | |||
| 81 | return false; |
||
| 82 | } |
||
| 83 | foreach ($signalAttr as $attr => $val) { |
||
| 84 | if ($signal->{$attr} !== $val) { |
||
| 85 | $that->fail( |
||
| 86 | "The attribute '{$attr}' of the signal does not have the correct value '{$val}'" |
||
| 87 | ); |
||
| 88 | |||
| 89 | return false; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | return true; |
||
| 94 | } |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | $service = $this->getSignalSlotService($innerService, $dispatcher); |
||
| 99 | $result = call_user_func_array(array($service, $method), $parameters); |
||
| 100 | |||
| 101 | $this->assertTrue($result === $return); |
||
| 102 | } |
||
| 103 | |||
| 200 |