| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| 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 |
||
| 15 | public function testSyncAll() |
||
| 16 | { |
||
| 17 | $xml = <<<XML |
||
| 18 | <?xml version="1.0"?> |
||
| 19 | <APIResponse version="20170228"> |
||
| 20 | <Header> |
||
| 21 | <Date>2016-01-07T23:43:20+01:00</Date> |
||
| 22 | <Path>API/getTerminals</Path> |
||
| 23 | <ErrorCode>0</ErrorCode> |
||
| 24 | <ErrorMessage></ErrorMessage> |
||
| 25 | </Header> |
||
| 26 | <Body> |
||
| 27 | <Result>Success</Result> |
||
| 28 | <Terminals> |
||
| 29 | <Terminal> |
||
| 30 | <Title>AltaPay Multi-Nature Terminal</Title> |
||
| 31 | <Country>DK</Country> |
||
| 32 | <Natures> |
||
| 33 | <Nature>CreditCard</Nature> |
||
| 34 | <Nature>EPayment</Nature> |
||
| 35 | <Nature>IdealPayment</Nature> |
||
| 36 | <Nature>Invoice</Nature> |
||
| 37 | </Natures> |
||
| 38 | <Currencies> |
||
| 39 | <Currency>DKK</Currency> |
||
| 40 | <Currency>EUR</Currency> |
||
| 41 | </Currencies> |
||
| 42 | </Terminal> |
||
| 43 | <Terminal> |
||
| 44 | <Title>AltaPay BankPayment Terminal</Title> |
||
| 45 | <Country></Country> |
||
| 46 | <Natures> |
||
| 47 | <Nature>BankPayment</Nature> |
||
| 48 | </Natures> |
||
| 49 | <Currencies> |
||
| 50 | <Currency>EUR</Currency> |
||
| 51 | </Currencies> |
||
| 52 | </Terminal> |
||
| 53 | </Terminals> |
||
| 54 | </Body> |
||
| 55 | </APIResponse> |
||
| 56 | XML; |
||
| 57 | |||
| 58 | $terminal = $this->createMock(Terminal::class); |
||
| 59 | |||
| 60 | $psrResponse = $this->createMock(ResponseInterface::class); |
||
| 61 | $psrResponse |
||
| 62 | ->expects($this->any()) |
||
| 63 | ->method('getBody') |
||
| 64 | ->willReturn($xml) |
||
| 65 | ; |
||
| 66 | $getTerminalsResponse = new GetTerminals($psrResponse); |
||
| 67 | |||
| 68 | /** @var TerminalManager|\PHPUnit_Framework_MockObject_MockObject $terminalManager */ |
||
| 69 | $terminalManager = $this->getMockBuilder(TerminalManager::class) |
||
| 70 | ->disableOriginalConstructor() |
||
| 71 | ->setMethods(['create', 'update', 'findTerminalByTitle']) |
||
| 72 | ->getMock() |
||
| 73 | ; |
||
| 74 | |||
| 75 | $terminalManager |
||
|
|
|||
| 76 | ->expects($this->any()) |
||
| 77 | ->method('create') |
||
| 78 | ->willReturn($terminal) |
||
| 79 | ; |
||
| 80 | |||
| 81 | $terminalManager |
||
| 82 | ->expects($this->any()) |
||
| 83 | ->method('update') |
||
| 84 | ->willReturn(null) |
||
| 85 | ; |
||
| 86 | |||
| 87 | $terminalManager |
||
| 88 | ->expects($this->any()) |
||
| 89 | ->method('findTerminalByTitle') |
||
| 90 | ->willReturn(null) |
||
| 91 | ; |
||
| 92 | |||
| 93 | $altapayClient = $this->createMock(Client::class); |
||
| 94 | $altapayClient |
||
| 95 | ->expects($this->any()) |
||
| 96 | ->method('getTerminals') |
||
| 97 | ->willReturn($getTerminalsResponse) |
||
| 98 | ; |
||
| 99 | |||
| 100 | $terminalSynchronizer = new TerminalSynchronizer($terminalManager, $altapayClient); |
||
| 101 | $terminalSynchronizer->syncAll(); |
||
| 102 | |||
| 103 | $this->assertTrue(true); |
||
| 104 | } |
||
| 105 | } |
||
| 106 |
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: