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 |
||
18 | class FrontMatterTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | /** |
||
21 | * @dataProvider getYaml |
||
22 | */ |
||
23 | View Code Duplication | public function testParseYaml($string, $data, $content) |
|
32 | |||
33 | /** |
||
34 | * @dataProvider getYaml |
||
35 | */ |
||
36 | View Code Duplication | public function testDumpYaml($string, $data, $content) |
|
43 | |||
44 | /** |
||
45 | * @dataProvider getSeparator |
||
46 | */ |
||
47 | View Code Duplication | public function testParseYamlWithCustomSeparator($string, $data, $content) |
|
56 | |||
57 | /** |
||
58 | * @dataProvider getSeparator |
||
59 | */ |
||
60 | View Code Duplication | public function testDumpYamlWithCustomSeparator($string, $data, $content) |
|
67 | |||
68 | /** |
||
69 | * @dataProvider getJson |
||
70 | */ |
||
71 | View Code Duplication | public function testParseJson($string, $data, $content) |
|
81 | |||
82 | /** |
||
83 | * @dataProvider getJson |
||
84 | */ |
||
85 | View Code Duplication | public function testDumpToJson($string, $data, $content) |
|
92 | |||
93 | View Code Duplication | public function getYaml() |
|
101 | |||
102 | View Code Duplication | public function getSeparator() |
|
110 | |||
111 | View Code Duplication | public function getJson() |
|
119 | } |
||
120 |
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.