Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 12 | class UpdateUserTest extends TestCase |
||
| 13 | { |
||
| 14 | |||
| 15 | private $endpoint = '/users'; |
||
| 16 | |||
| 17 | public function testUpdateExistingUser_() |
||
| 43 | |||
| 44 | View Code Duplication | public function testUpdateExistingUserWithEmptyValues() |
|
| 63 | |||
| 64 | // TODO: after upgrading to Laravel 5.2 this function started returning 500 instead of 403 |
||
| 65 | // it could be due to something in `app/Port/Exception/Handler/ExceptionsHandler.php` and the don't report thingy |
||
| 66 | // same problem as testDeleteDifferentUser |
||
| 67 | |||
| 68 | // public function testUpdateDifferentUser_() |
||
| 69 | // { |
||
| 70 | // $data = [ |
||
| 71 | // 'name' => 'Updated Name', |
||
| 72 | // 'password' => 'updated#Password', |
||
| 73 | // ]; |
||
| 74 | // |
||
| 75 | // $endpoint = $this->endpoint . '/' . 100; // amy ID |
||
| 76 | // |
||
| 77 | // // send the HTTP request |
||
| 78 | // $response = $this->apiCall($endpoint, 'put', $data); |
||
| 79 | // |
||
| 80 | // // assert response status is correct |
||
| 81 | // $this->assertEquals($response->getStatusCode(), '403'); |
||
| 82 | // |
||
| 83 | // // assert the message means (not allowed to proceed with the request) |
||
| 84 | // $this->assertEquals($response->getContent(), 'Forbidden'); |
||
| 85 | // } |
||
| 86 | |||
| 87 | } |
||
| 88 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.