Conditions | 2 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 52 |
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 |
||
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('Test', $parts); |
||
62 | $this->assertSame('a,b', $parts['Test']); |
||
63 | $this->assertArrayHasKey('Operation', $parts); |
||
64 | $this->assertSame('ItemLookup', $parts['Operation']); |
||
65 | $this->assertArrayHasKey('Service', $parts); |
||
66 | $this->assertSame('AWSECommerceService', $parts['Service']); |
||
67 | $this->assertArrayHasKey('Timestamp', $parts); |
||
68 | $this->assertRegExp('#[0-9]{4}(-[0-9]{2}){2}T([0-9]{2}:){2}[0-9]{2}Z#', $parts['Timestamp']); |
||
69 | $this->assertArrayHasKey('Version', $parts); |
||
70 | $this->assertSame('2013-08-01', $parts['Version']); |
||
71 | $this->assertArrayHasKey('Signature', $parts); |
||
72 | return true; |
||
73 | })) |
||
74 | ->shouldBeCalledTimes(1) |
||
75 | ->willReturn($response->reveal()); |
||
76 | |||
77 | $request = new GuzzleRequest($client->reveal()); |
||
78 | |||
79 | $operation = new Lookup(); |
||
80 | $operation->setItemId('1'); |
||
81 | $operation->setTest(['a', 'b']); |
||
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 | |||
149 |