Conditions | 2 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 32 |
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 |
||
12 | public function testBatchWithFailingMethod() |
||
13 | { |
||
14 | $client = self::createClient(); |
||
15 | |||
16 | $response = $this->sendRequest( |
||
17 | $client, |
||
18 | '/test/', |
||
19 | [ |
||
20 | [ |
||
21 | 'jsonrpc' => JsonRpcBundle::VERSION, |
||
22 | 'method' => 'sample', |
||
23 | 'id' => 'test', |
||
24 | 'params' => [ |
||
25 | 'param1' => 'value1', |
||
26 | 'param2' => 100500, |
||
27 | ], |
||
28 | ], |
||
29 | [ |
||
30 | 'jsonrpc' => JsonRpcBundle::VERSION, |
||
31 | 'method' => 'exception', |
||
32 | 'id' => 'test2', |
||
33 | 'params' => [ |
||
34 | 'param1' => 'value1', |
||
35 | 'param2' => 100500, |
||
36 | ], |
||
37 | ], |
||
38 | [ |
||
39 | //notification - no id |
||
40 | 'jsonrpc' => JsonRpcBundle::VERSION, |
||
41 | 'method' => 'notification', |
||
42 | 'param' => [ |
||
43 | 'notification' => 'message', |
||
44 | ], |
||
45 | ], |
||
46 | ] |
||
47 | ); |
||
48 | |||
49 | self::assertTrue($response->isSuccessful(), $response->getContent()); |
||
50 | $body = json_decode($response->getContent()); |
||
51 | self::assertTrue(is_array($body)); |
||
52 | self::assertCount(2, $body, json_encode($body, JSON_PRETTY_PRINT)); |
||
53 | |||
54 | /** @var JsonRpcResponseInterface[] $jsonResponses */ |
||
55 | $jsonResponses = []; |
||
56 | foreach ($body as $responseBody) { |
||
57 | $jsonResponses[] = new SyncResponse($responseBody); |
||
58 | } |
||
59 | |||
60 | self::assertTrue($jsonResponses[0]->isSuccessful()); |
||
61 | self::assertFalse($jsonResponses[1]->isSuccessful()); |
||
62 | self::assertEquals(JsonRpcError::INTERNAL_ERROR, $jsonResponses[1]->getError()->getCode()); |
||
63 | self::assertEquals('This is the malfunction controller', $jsonResponses[1]->getError()->getMessage()); |
||
64 | } |
||
65 | |||
111 |