| Conditions | 2 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 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 |
||
| 28 | public function testPerform() |
||
| 29 | { |
||
| 30 | $body = $this->prophesize('\Psr\Http\Message\StreamInterface'); |
||
| 31 | $body |
||
| 32 | ->getContents() |
||
| 33 | ->shouldBeCalledTimes(1) |
||
| 34 | ->willReturn('ABC'); |
||
| 35 | |||
| 36 | $response = $this->prophesize('\Psr\Http\Message\ResponseInterface'); |
||
| 37 | $response |
||
| 38 | ->getBody() |
||
| 39 | ->shouldBeCalledTimes(1) |
||
| 40 | ->willReturn($body->reveal()); |
||
| 41 | |||
| 42 | $client = $this->prophesize('\GuzzleHttp\ClientInterface'); |
||
| 43 | $client |
||
| 44 | ->send(Argument::that(function ($request) { |
||
| 45 | if (!$request instanceof RequestInterface) { |
||
| 46 | return false; |
||
| 47 | } |
||
| 48 | |||
| 49 | $uri = $request->getUri(); |
||
| 50 | $parts = []; |
||
| 51 | parse_str($uri->getQuery(), $parts); |
||
| 52 | |||
| 53 | $this->assertSame('webservices.amazon.de', $uri->getHost()); |
||
| 54 | $this->assertSame('/onca/xml', $uri->getPath()); |
||
| 55 | $this->assertArrayHasKey('AWSAccessKeyId', $parts); |
||
| 56 | $this->assertSame('jkl', $parts['AWSAccessKeyId']); |
||
| 57 | $this->assertArrayHasKey('AssociateTag', $parts); |
||
| 58 | $this->assertSame('def', $parts['AssociateTag']); |
||
| 59 | $this->assertArrayHasKey('ItemId', $parts); |
||
| 60 | $this->assertSame('1', $parts['ItemId']); |
||
| 61 | $this->assertArrayHasKey('Operation', $parts); |
||
| 62 | $this->assertSame('ItemLookup', $parts['Operation']); |
||
| 63 | $this->assertArrayHasKey('Service', $parts); |
||
| 64 | $this->assertSame('AWSECommerceService', $parts['Service']); |
||
| 65 | $this->assertArrayHasKey('Timestamp', $parts); |
||
| 66 | $this->assertRegExp('#[0-9]{4}(-[0-9]{2}){2}T([0-9]{2}:){2}[0-9]{2}Z#', $parts['Timestamp']); |
||
| 67 | $this->assertArrayHasKey('Version', $parts); |
||
| 68 | $this->assertSame('2011-08-01', $parts['Version']); |
||
| 69 | $this->assertArrayHasKey('Signature', $parts); |
||
| 70 | return true; |
||
| 71 | })) |
||
| 72 | ->shouldBeCalledTimes(1) |
||
| 73 | ->willReturn($response->reveal()); |
||
| 74 | |||
| 75 | $request = new Request($client->reveal()); |
||
| 76 | |||
| 77 | $operation = new Lookup(); |
||
| 78 | $operation->setItemId('1'); |
||
| 79 | |||
| 80 | $config = new GenericConfiguration(); |
||
| 81 | $config->setAccessKey('abc'); |
||
| 82 | $config->setAssociateTag('def'); |
||
| 83 | $config->setCountry('DE'); |
||
| 84 | $config->setSecretKey('ghi'); |
||
| 85 | $config->setAccessKey('jkl'); |
||
| 86 | |||
| 87 | $request->perform($operation, $config); |
||
| 88 | } |
||
| 89 | |||
| 146 |