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 |
||
21 | class FileLoaderTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
||
25 | */ |
||
26 | public $router; |
||
27 | /** |
||
28 | * @var FileLoader |
||
29 | */ |
||
30 | public $loader; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | public $vars; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | public $file; |
||
41 | |||
42 | /** |
||
43 | * PHP Route File Loader setUp |
||
44 | */ |
||
45 | public function setUp() |
||
57 | |||
58 | /** |
||
59 | * |
||
60 | */ |
||
61 | View Code Duplication | public function testLoadFileNoCacheNonInvalidFile() |
|
69 | |||
70 | /** |
||
71 | * |
||
72 | */ |
||
73 | View Code Duplication | public function testLoadFileNoCacheNoFile() |
|
81 | |||
82 | /** |
||
83 | * |
||
84 | */ |
||
85 | View Code Duplication | public function testLoadFileNoCacheWithVars() |
|
99 | |||
100 | /** |
||
101 | * |
||
102 | */ |
||
103 | View Code Duplication | public function testLoadFileWithCache() |
|
115 | |||
116 | /** |
||
117 | * |
||
118 | */ |
||
119 | View Code Duplication | public function testLoadFilesNoCacheNoFile() |
|
133 | |||
134 | /** |
||
135 | * |
||
136 | */ |
||
137 | View Code Duplication | public function testLoadFilesNoCache() |
|
152 | |||
153 | /** |
||
154 | * |
||
155 | */ |
||
156 | public function testLoadFilesCache() |
||
167 | } |
||
168 |
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.