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 |
||
20 | class VichSerializableFieldTest extends \PHPUnit_Framework_TestCase |
||
21 | { |
||
22 | /** |
||
23 | * Test annotation with `value` option |
||
24 | */ |
||
25 | View Code Duplication | public function testValueOption() |
|
32 | |||
33 | /** |
||
34 | * Test annotation with `field` option |
||
35 | */ |
||
36 | View Code Duplication | public function testFieldOption() |
|
43 | |||
44 | /** |
||
45 | * Test annotation with `value` and `includeHost` options |
||
46 | */ |
||
47 | View Code Duplication | public function testValueAndIncludeHostOptions() |
|
54 | |||
55 | /** |
||
56 | * Test annotation without any option |
||
57 | * |
||
58 | * @expectedException \LogicException |
||
59 | */ |
||
60 | public function testAnnotationWithoutOptions() |
||
64 | |||
65 | /** |
||
66 | * Test annotation without `value` or `field` options |
||
67 | * |
||
68 | * @expectedException \LogicException |
||
69 | */ |
||
70 | public function testAnnotationWithoutIncludeHostOption() |
||
74 | |||
75 | /** |
||
76 | * Test annotation with wrong type for `value` option |
||
77 | * |
||
78 | * @expectedException \InvalidArgumentException |
||
79 | */ |
||
80 | public function testWrongTypeForValueOption() |
||
84 | |||
85 | /** |
||
86 | * Test annotation with wrong type for `field` option |
||
87 | * |
||
88 | * @expectedException \InvalidArgumentException |
||
89 | */ |
||
90 | public function testWrongTypeForFieldOption() |
||
94 | |||
95 | /** |
||
96 | * Test annotation with wrong type for `includeHost` option |
||
97 | * |
||
98 | * @expectedException \InvalidArgumentException |
||
99 | */ |
||
100 | public function testWrongTypeForFieldIncludeHost() |
||
104 | } |
||
105 |
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.