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 |
||
10 | View Code Duplication | class DirectLinkMaintenanceResponseTest extends \PHPUnit_Framework_TestCase |
|
|
|||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @test |
||
15 | * @expectedException InvalidArgumentException |
||
16 | */ |
||
17 | public function CantExistWithoutXmlFile() |
||
21 | |||
22 | /** @test */ |
||
23 | public function ParametersCanBeRetrieved() |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | * @expectedException InvalidArgumentException |
||
34 | */ |
||
35 | public function RequestIsFilteredFromNonOgoneParameters() |
||
42 | |||
43 | /** |
||
44 | * @test |
||
45 | * @expectedException InvalidArgumentException |
||
46 | */ |
||
47 | public function ChecksInvalidXml() |
||
53 | |||
54 | /** @test */ |
||
55 | public function ChecksStatus() |
||
62 | |||
63 | /** @test */ |
||
64 | public function AmountIsConvertedToCent() |
||
71 | |||
72 | public function provideFloats() |
||
80 | |||
81 | /** |
||
82 | * @test |
||
83 | * @dataProvider provideFloats |
||
84 | */ |
||
85 | public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
||
92 | |||
93 | /** |
||
94 | * Helper method to setup an xml-string |
||
95 | */ |
||
96 | private function provideXML($amount = null) |
||
113 | |||
114 | /** |
||
115 | * Helper method to setup an invalid xml-string |
||
116 | */ |
||
117 | private function provideInvalidXML() |
||
125 | } |
||
126 |
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.