| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 48 | public function testPublish(Topic $topic, PubSubClient $client, $setLogger, $logInfoCallsCount, $message) |
||
|
|
|||
| 49 | { |
||
| 50 | $publisher = new Publisher(self::TOPIC, $client, $this->serializer); |
||
| 51 | |||
| 52 | $message = new TestPublishMessageDTO(uniqid('test_')); |
||
| 53 | $result = (new TestPublishMessageResultDTO()) |
||
| 54 | ->setMessageIds([uniqid('test_')]) |
||
| 55 | ; |
||
| 56 | |||
| 57 | $serializer = SerializerBuilder::create()->build(); |
||
| 58 | $serializedData = $serializer->serialize($message, 'json'); |
||
| 59 | $serializedResult = $serializer->toArray($result); |
||
| 60 | |||
| 61 | $this->serializer |
||
| 62 | ->expects($this->once()) |
||
| 63 | ->method('serialize') |
||
| 64 | ->with($message, 'json') |
||
| 65 | ->willReturn($serializedData) |
||
| 66 | ; |
||
| 67 | |||
| 68 | $this->serializer |
||
| 69 | ->expects($this->once()) |
||
| 70 | ->method('fromArray') |
||
| 71 | ->with($serializedResult) |
||
| 72 | ->willReturn($result) |
||
| 73 | ; |
||
| 74 | |||
| 75 | $topic |
||
| 76 | ->expects($this->once()) |
||
| 77 | ->method('publish') |
||
| 78 | ->with(['data' => $serializedData], []) |
||
| 79 | ->willReturn($serializedResult) |
||
| 80 | ; |
||
| 81 | |||
| 82 | if ($setLogger) { |
||
| 83 | $logger = $this->getMockBuilder('Psr\Log\LoggerInterface') |
||
| 84 | ->disableOriginalConstructor() |
||
| 85 | ->getMock() |
||
| 86 | ; |
||
| 87 | |||
| 88 | $logger |
||
| 89 | ->expects($this->exactly($logInfoCallsCount)) |
||
| 90 | ->method('info') |
||
| 91 | ; |
||
| 92 | |||
| 93 | $publisher->setLogger($logger); |
||
| 94 | } |
||
| 95 | |||
| 96 | $actualResult = $publisher->publish($message); |
||
| 97 | $this->assertEquals($result, $actualResult); |
||
| 98 | } |
||
| 99 | |||
| 154 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.