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 YamlLoaderTest extends \PHPUnit_Framework_TestCase |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
||
20 | */ |
||
21 | public $router; |
||
22 | |||
23 | /** |
||
24 | * @var YamlLoader |
||
25 | */ |
||
26 | public $loader; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | public $file; |
||
32 | |||
33 | /** |
||
34 | * |
||
35 | */ |
||
36 | public function setUp() |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | */ |
||
46 | View Code Duplication | public function testLoadFileNoCacheParse() |
|
56 | |||
57 | /** |
||
58 | * |
||
59 | */ |
||
60 | View Code Duplication | public function testLoadFileNoCacheNoFile() |
|
70 | |||
71 | /** |
||
72 | * |
||
73 | */ |
||
74 | View Code Duplication | public function testLoadFileNoCache() |
|
89 | |||
90 | /** |
||
91 | * |
||
92 | */ |
||
93 | View Code Duplication | public function testLoadFileCache() |
|
107 | |||
108 | /** |
||
109 | * |
||
110 | */ |
||
111 | View Code Duplication | public function testLoadFilesNoCache() |
|
126 | } |
||
127 |
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.