| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 30 |
| 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 |
||
| 14 | public function testSyncAll() |
||
| 15 | { |
||
| 16 | $xml = <<<XML |
||
| 17 | <?xml version="1.0"?> |
||
| 18 | <APIResponse version="20170228"> |
||
| 19 | <Header> |
||
| 20 | <Date>2016-01-07T23:43:20+01:00</Date> |
||
| 21 | <Path>API/getTerminals</Path> |
||
| 22 | <ErrorCode>0</ErrorCode> |
||
| 23 | <ErrorMessage></ErrorMessage> |
||
| 24 | </Header> |
||
| 25 | <Body> |
||
| 26 | <Result>Success</Result> |
||
| 27 | <Terminals> |
||
| 28 | <Terminal> |
||
| 29 | <Title>AltaPay Multi-Nature Terminal</Title> |
||
| 30 | <Country>DK</Country> |
||
| 31 | <Natures> |
||
| 32 | <Nature>CreditCard</Nature> |
||
| 33 | <Nature>EPayment</Nature> |
||
| 34 | <Nature>IdealPayment</Nature> |
||
| 35 | <Nature>Invoice</Nature> |
||
| 36 | </Natures> |
||
| 37 | <Currencies> |
||
| 38 | <Currency>DKK</Currency> |
||
| 39 | <Currency>EUR</Currency> |
||
| 40 | </Currencies> |
||
| 41 | </Terminal> |
||
| 42 | <Terminal> |
||
| 43 | <Title>AltaPay BankPayment Terminal</Title> |
||
| 44 | <Country></Country> |
||
| 45 | <Natures> |
||
| 46 | <Nature>BankPayment</Nature> |
||
| 47 | </Natures> |
||
| 48 | <Currencies> |
||
| 49 | <Currency>EUR</Currency> |
||
| 50 | </Currencies> |
||
| 51 | </Terminal> |
||
| 52 | </Terminals> |
||
| 53 | </Body> |
||
| 54 | </APIResponse> |
||
| 55 | XML; |
||
| 56 | |||
| 57 | $psrResponse = $this->createMock(ResponseInterface::class); |
||
| 58 | $psrResponse |
||
| 59 | ->expects($this->any()) |
||
| 60 | ->method('getBody') |
||
| 61 | ->willReturn($xml) |
||
| 62 | ; |
||
| 63 | $getTerminalsResponse = new GetTerminals($psrResponse); |
||
|
|
|||
| 64 | |||
| 65 | /** @var TerminalRepository|\PHPUnit_Framework_MockObject_MockObject $terminalRepository */ |
||
| 66 | $terminalRepository = $this->getMockBuilder(TerminalRepository::class) |
||
| 67 | ->disableOriginalConstructor() |
||
| 68 | ->setMethods(['save', 'findTerminalByTitle']) |
||
| 69 | ->getMock() |
||
| 70 | ; |
||
| 71 | |||
| 72 | $terminalRepository |
||
| 73 | ->expects($this->any()) |
||
| 74 | ->method('save') |
||
| 75 | ->willReturn(null) |
||
| 76 | ; |
||
| 77 | |||
| 78 | $terminalRepository |
||
| 79 | ->expects($this->any()) |
||
| 80 | ->method('findTerminalByTitle') |
||
| 81 | ->willReturn(null) |
||
| 82 | ; |
||
| 83 | |||
| 84 | $altapayClient = $this->createMock(Client::class); |
||
| 85 | $altapayClient |
||
| 86 | ->expects($this->any()) |
||
| 87 | ->method('getTerminals') |
||
| 88 | ->willReturn($getTerminalsResponse) |
||
| 89 | ; |
||
| 90 | |||
| 91 | $terminalSynchronizer = new TerminalSynchronizer($terminalRepository, $altapayClient); |
||
| 92 | $terminalSynchronizer->syncAll(); |
||
| 93 | |||
| 94 | $this->assertTrue(true); |
||
| 95 | } |
||
| 96 | } |
||
| 97 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: