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