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 |
||
13 | class LuaInputStreamTest extends \PHPUnit_Framework_TestCase { |
||
14 | public function testSimpleNext() { |
||
18 | |||
19 | View Code Duplication | public function testMultipleLines() { |
|
28 | |||
29 | /** |
||
30 | * @expectedException \Vlaswinkel\Lua\LuaParseException |
||
31 | * @expectedExceptionMessage Simple error (1:1) |
||
32 | */ |
||
33 | public function testSimpleError() { |
||
39 | |||
40 | /** |
||
41 | * @expectedException \Vlaswinkel\Lua\LuaParseException |
||
42 | * @expectedExceptionMessage Other error (2:1) |
||
43 | */ |
||
44 | View Code Duplication | public function testMultipleLineError() { |
|
52 | |||
53 | /** |
||
54 | * @expectedException \Vlaswinkel\Lua\LuaParseException |
||
55 | * @expectedExceptionMessage This error (1:2) |
||
56 | */ |
||
57 | View Code Duplication | public function testMultipleColumnError() { |
|
64 | |||
65 | /** |
||
66 | * @expectedException \Vlaswinkel\Lua\LuaParseException |
||
67 | * @expectedExceptionMessage Complex error (2:2) |
||
68 | */ |
||
69 | View Code Duplication | public function testMultipleLineAndColumnError() { |
|
80 | } |
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.