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 | View Code Duplication | class TextFormSubmissionFieldTest extends TestCase |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @var TextFormSubmissionField |
||
16 | */ |
||
17 | protected $object; |
||
18 | |||
19 | /** |
||
20 | * Sets up the fixture, for example, opens a network connection. |
||
21 | * This method is called before a test is executed. |
||
22 | */ |
||
23 | protected function setUp() |
||
27 | |||
28 | /** |
||
29 | * @covers \Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\TextFormSubmissionField::getValue |
||
30 | * @covers \Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\TextFormSubmissionField::setValue |
||
31 | */ |
||
32 | public function testGetSetValue() |
||
39 | |||
40 | /** |
||
41 | * @covers \Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\TextFormSubmissionField::getDefaultAdminType |
||
42 | */ |
||
43 | public function testGetDefaultAdminType() |
||
47 | |||
48 | /** |
||
49 | * @covers \Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\TextFormSubmissionField::__toString |
||
50 | */ |
||
51 | public function testToString() |
||
57 | } |
||
58 |
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.