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 declare(strict_types = 1); |
||
21 | class RbacApiTest extends WebTestCase |
||
22 | { |
||
23 | use ApiTestCase; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $env = 'secure_rbac'; |
||
29 | |||
30 | protected function setUp() |
||
34 | |||
35 | /** |
||
36 | * @test |
||
37 | */ |
||
38 | public function canGetUserContentAsUser() |
||
46 | |||
47 | /** |
||
48 | * @test |
||
49 | */ |
||
50 | View Code Duplication | public function cannotGetUserContentAsGuest() |
|
61 | |||
62 | /** |
||
63 | * @test |
||
64 | */ |
||
65 | public function cannotGetUserContentWithoutAuth() |
||
74 | |||
75 | /** |
||
76 | * @test |
||
77 | */ |
||
78 | public function canGetAdminContentAsAdmin() |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | */ |
||
90 | View Code Duplication | public function cannotGetAdminContentAsUser() |
|
101 | |||
102 | private function createClientForUser(string $user) |
||
111 | } |
||
112 |
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.