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 |
||
| 15 | class RoleTest extends DriverEntityKernelTestBase |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Machine name of the entity type being tested. |
||
| 20 | * |
||
| 21 | * @string |
||
| 22 | */ |
||
| 23 | protected $entityType = 'user_role'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Our entity is a config entity. |
||
| 27 | * |
||
| 28 | * @boolean |
||
| 29 | */ |
||
| 30 | protected $config = true; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Test that a role can be created and deleted. |
||
| 34 | */ |
||
| 35 | public function testRoleCreateDelete() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Test that a role can be created and deleted. |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function testRoleCreateDeleteNew() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Test that an exception is thrown if config property is missing. |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function testMissingConfigProperty() |
|
| 90 | } |
||
| 91 |
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.