Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
41 | public function testActionsSingle() |
||
42 | { |
||
43 | $client = static::createClient( array(), array( |
||
44 | 'PHP_AUTH_USER' => 'admin', |
||
45 | 'PHP_AUTH_PW' => 'adminpass', |
||
46 | ) ); |
||
47 | |||
48 | |||
49 | $content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"symfony","stock.type.label":"symfony"}}}'; |
||
50 | $client->request( 'POST', '/unittest/jsonadm/stock/type', array(), array(), array(), $content ); |
||
51 | $response = $client->getResponse(); |
||
52 | |||
53 | $json = json_decode( $response->getContent(), true ); |
||
54 | |||
55 | $this->assertNotNull( $json ); |
||
56 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
57 | $this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
||
58 | $this->assertEquals( 'symfony', $json['data']['attributes']['stock.type.code'] ); |
||
59 | $this->assertEquals( 'symfony', $json['data']['attributes']['stock.type.label'] ); |
||
60 | $this->assertEquals( 1, $json['meta']['total'] ); |
||
61 | |||
62 | $id = $json['data']['attributes']['stock.type.id']; |
||
63 | |||
64 | |||
65 | $content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"symfony2","stock.type.label":"symfony2"}}}'; |
||
66 | $client->request( 'PATCH', '/unittest/jsonadm/stock/type/' . $id, array(), array(), array(), $content ); |
||
67 | $response = $client->getResponse(); |
||
68 | |||
69 | $json = json_decode( $response->getContent(), true ); |
||
70 | |||
71 | $this->assertNotNull( $json ); |
||
72 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
73 | $this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
||
74 | $this->assertEquals( 'symfony2', $json['data']['attributes']['stock.type.code'] ); |
||
75 | $this->assertEquals( 'symfony2', $json['data']['attributes']['stock.type.label'] ); |
||
76 | $this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] ); |
||
77 | $this->assertEquals( 1, $json['meta']['total'] ); |
||
78 | |||
79 | |||
80 | $client->request( 'GET', '/unittest/jsonadm/stock/type/' . $id ); |
||
81 | $response = $client->getResponse(); |
||
82 | |||
83 | $json = json_decode( $response->getContent(), true ); |
||
84 | |||
85 | $this->assertNotNull( $json ); |
||
86 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
87 | $this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
||
88 | $this->assertEquals( 'symfony2', $json['data']['attributes']['stock.type.code'] ); |
||
89 | $this->assertEquals( 'symfony2', $json['data']['attributes']['stock.type.label'] ); |
||
90 | $this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] ); |
||
91 | $this->assertEquals( 1, $json['meta']['total'] ); |
||
92 | |||
93 | |||
94 | $client->request( 'DELETE', '/unittest/jsonadm/stock/type/' . $id ); |
||
95 | $response = $client->getResponse(); |
||
96 | |||
97 | $json = json_decode( $response->getContent(), true ); |
||
98 | |||
99 | $this->assertNotNull( $json ); |
||
100 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
101 | $this->assertEquals( 1, $json['meta']['total'] ); |
||
102 | } |
||
192 |