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