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 |
||
| 9 | class LikeDislikeAPITest extends TestCase |
||
|
|
|||
| 10 | { |
||
| 11 | use DatabaseMigrations; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Create fake user. |
||
| 15 | * |
||
| 16 | * @return mixed |
||
| 17 | */ |
||
| 18 | public function createUser() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param User $user |
||
| 28 | * |
||
| 29 | * @return mixed |
||
| 30 | */ |
||
| 31 | private function createUserApiKey(User $user) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Create fake video. |
||
| 39 | * |
||
| 40 | * @return \App\Video |
||
| 41 | */ |
||
| 42 | View Code Duplication | private function createFakeVideo($user) |
|
| 55 | |||
| 56 | View Code Duplication | private function createFakeLikes($video_id) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Test likes in database are listed by API. |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function testLikesInDatabaseAreListedByAPI() |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Test dislikes in database are listed by API. |
||
| 100 | * |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | View Code Duplication | public function testDislikesInDatabaseAreListedByAPI() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Test likes count return integer. |
||
| 119 | * |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function testLikesCountReturnInteger() |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Test dislikes count return integer. |
||
| 133 | * |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | View Code Duplication | public function testDisikesCountReturnInteger() |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Test store like and see in DB. |
||
| 147 | * |
||
| 148 | * @return void |
||
| 149 | */ |
||
| 150 | View Code Duplication | public function testCanBePostLikeAndSeeInDB() |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Test delete likeDislike and not see in DB. |
||
| 167 | * |
||
| 168 | * @return void |
||
| 169 | */ |
||
| 170 | View Code Duplication | public function testCanBeDeleteLikeAndSeeInDB() |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Test update type likeDislike and not see in DB. |
||
| 189 | * |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | public function testCanBeUpdateTypeLikeAndSeeInDB() |
||
| 214 | } |
||
| 215 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.