| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 35 |
| 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 |
||
| 25 | public function shouldSuccessCallsWithPriority() |
||
| 26 | { |
||
| 27 | $message = self::createMock(Message::class); |
||
| 28 | $request = self::createMock(Request::class); |
||
| 29 | |||
| 30 | $visitor1 = $this->createVisitor(); |
||
| 31 | $visitor2 = $this->createVisitor(); |
||
| 32 | $visitor3 = $this->createVisitor(); |
||
| 33 | |||
| 34 | $calls = []; |
||
| 35 | |||
| 36 | $visitor3->expects(self::exactly(2)) |
||
|
|
|||
| 37 | ->method('visit') |
||
| 38 | ->with($message, $request) |
||
| 39 | ->willReturnCallback(function () use (&$calls, $request) { |
||
| 40 | $calls[] = 3; |
||
| 41 | |||
| 42 | return $request; |
||
| 43 | }); |
||
| 44 | |||
| 45 | $visitor1->expects(self::exactly(2)) |
||
| 46 | ->method('visit') |
||
| 47 | ->with($message, $request) |
||
| 48 | ->willReturnCallback(function () use (&$calls, $request) { |
||
| 49 | $calls[] = 1; |
||
| 50 | |||
| 51 | return $request; |
||
| 52 | }); |
||
| 53 | |||
| 54 | $visitor2->expects(self::exactly(2)) |
||
| 55 | ->method('visit') |
||
| 56 | ->with($message, $request) |
||
| 57 | ->willReturnCallback(function () use (&$calls, $request) { |
||
| 58 | $calls[] = 2; |
||
| 59 | |||
| 60 | return $request; |
||
| 61 | }); |
||
| 62 | |||
| 63 | $chain = new HttpProtocolChainVisitor(); |
||
| 64 | $chain->add($visitor3, -1); |
||
| 65 | $chain->add($visitor1, 0); |
||
| 66 | $chain->add($visitor2, 1); |
||
| 67 | |||
| 68 | $chain->visit($message, $request); |
||
| 69 | // Call to second iteration |
||
| 70 | $chain->visit($message, $request); |
||
| 71 | |||
| 72 | self::assertEquals([ |
||
| 73 | 2, 1, 3, |
||
| 74 | 2, 1, 3, |
||
| 75 | ], $calls); |
||
| 76 | } |
||
| 77 | |||
| 129 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: