| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 105 | public function testActionsBulk() |
||
| 106 | { |
||
| 107 | $client = static::createClient( array(), array( |
||
| 108 | 'PHP_AUTH_USER' => 'admin', |
||
| 109 | 'PHP_AUTH_PW' => 'adminpass', |
||
| 110 | ) ); |
||
| 111 | |||
| 112 | |||
| 113 | $content = '{"data":[ |
||
| 114 | {"type":"stock/type","attributes":{"stock.type.code":"symfony","stock.type.label":"symfony"}}, |
||
| 115 | {"type":"stock/type","attributes":{"stock.type.code":"symfony2","stock.type.label":"symfony"}} |
||
| 116 | ]}'; |
||
| 117 | $client->request( 'POST', '/unittest/jsonadm/stock/type', array(), array(), array(), $content ); |
||
| 118 | $response = $client->getResponse(); |
||
| 119 | |||
| 120 | $json = json_decode( $response->getContent(), true ); |
||
| 121 | |||
| 122 | $this->assertNotNull( $json ); |
||
| 123 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
| 124 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 125 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 126 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 127 | $this->assertEquals( 'symfony', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 128 | $this->assertEquals( 'symfony', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 129 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 130 | |||
| 131 | $ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
||
| 132 | |||
| 133 | |||
| 134 | $content = '{"data":[ |
||
| 135 | {"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"symfony2"}}, |
||
| 136 | {"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"symfony2"}} |
||
| 137 | ]}'; |
||
| 138 | $client->request( 'PATCH', '/unittest/jsonadm/stock/type', array(), array(), array(), $content ); |
||
| 139 | $response = $client->getResponse(); |
||
| 140 | |||
| 141 | $json = json_decode( $response->getContent(), true ); |
||
| 142 | |||
| 143 | $this->assertNotNull( $json ); |
||
| 144 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 145 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 146 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 147 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 148 | $this->assertEquals( 'symfony2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 149 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 150 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 151 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 152 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 153 | |||
| 154 | |||
| 155 | $getParams = array( 'filter' => array( '&&' => array( |
||
| 156 | array( '=~' => array( 'stock.type.code' => 'symfony' ) ), |
||
| 157 | array( '==' => array( 'stock.type.label' => 'symfony2' ) ) |
||
| 158 | ) ), |
||
| 159 | 'sort' => 'stock.type.code', 'page' => array( 'offset' => 0, 'limit' => 3 ) |
||
| 160 | ); |
||
| 161 | $client->request( 'GET', '/unittest/jsonadm/stock/type', $getParams ); |
||
| 162 | $response = $client->getResponse(); |
||
| 163 | |||
| 164 | $json = json_decode( $response->getContent(), true ); |
||
| 165 | |||
| 166 | $this->assertNotNull( $json ); |
||
| 167 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 168 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 169 | $this->assertEquals( 'symfony', $json['data'][0]['attributes']['stock.type.code'] ); |
||
| 170 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.code'] ); |
||
| 171 | $this->assertEquals( 'symfony2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 172 | $this->assertEquals( 'symfony2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 173 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 174 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 175 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 176 | |||
| 177 | |||
| 178 | $content = '{"data":[ |
||
| 179 | {"type":"stock/type","id":' . $ids[0] . '}, |
||
| 180 | {"type":"stock/type","id":' . $ids[1] . '} |
||
| 181 | ]}'; |
||
| 182 | $client->request( 'DELETE', '/unittest/jsonadm/stock/type', array(), array(), array(), $content ); |
||
| 183 | $response = $client->getResponse(); |
||
| 184 | |||
| 185 | $json = json_decode( $response->getContent(), true ); |
||
| 186 | |||
| 187 | $this->assertNotNull( $json ); |
||
| 188 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
| 189 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 190 | } |
||
| 192 |