| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 55 |
| 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 |
||
| 107 | public function testActionsBulk() |
||
| 108 | { |
||
| 109 | $params = ['site' => 'unittest', 'resource' => 'stock/type']; |
||
| 110 | $content = '{"data":[ |
||
| 111 | {"type":"stock/type","attributes":{"stock.type.code":"laravel","stock.type.label":"laravel"}}, |
||
| 112 | {"type":"stock/type","attributes":{"stock.type.code":"laravel2","stock.type.label":"laravel"}} |
||
| 113 | ]}'; |
||
| 114 | $response = $this->action('POST', '\Aimeos\Shop\Controller\JsonadmController@postAction', $params, [], [], [], [], $content); |
||
| 115 | |||
| 116 | $json = json_decode( $response->getContent(), true ); |
||
| 117 | |||
| 118 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
| 119 | $this->assertNotNull( $json ); |
||
| 120 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 121 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 122 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 123 | $this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 124 | $this->assertEquals( 'laravel', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 125 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 126 | |||
| 127 | $ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
||
| 128 | |||
| 129 | |||
| 130 | $params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
||
| 131 | $content = '{"data":[ |
||
| 132 | {"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"laravel2"}}, |
||
| 133 | {"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"laravel2"}} |
||
| 134 | ]}'; |
||
| 135 | $response = $this->action('PATCH', '\Aimeos\Shop\Controller\JsonadmController@patchAction', $params, [], [], [], [], $content); |
||
| 136 | |||
| 137 | $json = json_decode( $response->getContent(), true ); |
||
| 138 | |||
| 139 | $this->assertResponseOk(); |
||
| 140 | $this->assertNotNull( $json ); |
||
| 141 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 142 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
| 143 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
| 144 | $this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 145 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 146 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 147 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 148 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 149 | |||
| 150 | |||
| 151 | $params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
||
| 152 | $getParams = ['filter' => ['&&' => [ |
||
| 153 | ['=~' => ['stock.type.code' => 'laravel']], |
||
| 154 | ['==' => ['stock.type.label' => 'laravel2']] |
||
| 155 | ]], |
||
| 156 | 'sort' => 'stock.type.code', 'page' => ['offset' => 0, 'limit' => 3] |
||
| 157 | ]; |
||
| 158 | $response = $this->action('GET', '\Aimeos\Shop\Controller\JsonadmController@getAction', $params, $getParams); |
||
| 159 | |||
| 160 | $json = json_decode( $response->getContent(), true ); |
||
| 161 | |||
| 162 | $this->assertResponseOk(); |
||
| 163 | $this->assertNotNull( $json ); |
||
| 164 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
| 165 | $this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.code'] ); |
||
| 166 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.code'] ); |
||
| 167 | $this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
| 168 | $this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
| 169 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
| 170 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
| 171 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 172 | |||
| 173 | |||
| 174 | $params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
||
| 175 | $content = '{"data":[ |
||
| 176 | {"type":"stock/type","id":' . $ids[0] . '}, |
||
| 177 | {"type":"stock/type","id":' . $ids[1] . '} |
||
| 178 | ]}'; |
||
| 179 | $response = $this->action('DELETE', '\Aimeos\Shop\Controller\JsonadmController@deleteAction', $params, [], [], [], [], $content); |
||
| 180 | |||
| 181 | $json = json_decode( $response->getContent(), true ); |
||
| 182 | |||
| 183 | $this->assertResponseOk(); |
||
| 184 | $this->assertNotNull( $json ); |
||
| 185 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
| 186 | } |
||
| 204 |