Conditions | 2 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 50 |
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 | |||
44 | $that = $this; |
||
45 | |||
46 | $client |
||
47 | ->send(Argument::that(function ($request) use ($that) { |
||
48 | if (!$request instanceof RequestInterface) { |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | $uri = $request->getUri(); |
||
53 | $parts = []; |
||
54 | parse_str($uri->getQuery(), $parts); |
||
55 | |||
56 | $that->assertSame('webservices.amazon.de', $uri->getHost()); |
||
57 | $that->assertSame('/onca/xml', $uri->getPath()); |
||
58 | $that->assertArrayHasKey('AWSAccessKeyId', $parts); |
||
59 | $that->assertSame('jkl', $parts['AWSAccessKeyId']); |
||
60 | $that->assertArrayHasKey('AssociateTag', $parts); |
||
61 | $that->assertSame('def', $parts['AssociateTag']); |
||
62 | $that->assertArrayHasKey('ItemId', $parts); |
||
63 | $that->assertSame('1', $parts['ItemId']); |
||
64 | $that->assertArrayHasKey('Operation', $parts); |
||
65 | $that->assertSame('ItemLookup', $parts['Operation']); |
||
66 | $that->assertArrayHasKey('Service', $parts); |
||
67 | $that->assertSame('AWSECommerceService', $parts['Service']); |
||
68 | $that->assertArrayHasKey('Timestamp', $parts); |
||
69 | $that->assertRegExp('#[0-9]{4}(-[0-9]{2}){2}T([0-9]{2}:){2}[0-9]{2}Z#', $parts['Timestamp']); |
||
70 | $that->assertArrayHasKey('Version', $parts); |
||
71 | $that->assertSame('2011-08-01', $parts['Version']); |
||
72 | $that->assertArrayHasKey('Signature', $parts); |
||
73 | return true; |
||
74 | })) |
||
75 | ->shouldBeCalledTimes(1) |
||
76 | ->willReturn($response->reveal()); |
||
77 | |||
78 | $request = new Request($client->reveal()); |
||
79 | |||
80 | $operation = new Lookup(); |
||
81 | $operation->setItemId('1'); |
||
82 | |||
83 | $config = new GenericConfiguration(); |
||
84 | $config->setAccessKey('abc'); |
||
85 | $config->setAssociateTag('def'); |
||
86 | $config->setCountry('DE'); |
||
87 | $config->setSecretKey('ghi'); |
||
88 | $config->setAccessKey('jkl'); |
||
89 | |||
90 | $request->perform($operation, $config); |
||
91 | } |
||
92 | } |
||
93 |