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 SimpleWalkerTest extends TextFileTestCase |
||
14 | { |
||
15 | /** |
||
16 | * @covers TextFile\Walker\SimpleWalker::goToLine |
||
17 | */ |
||
18 | public function testGoToLine() |
||
33 | |||
34 | /** |
||
35 | * @covers TextFile\Walker\SimpleWalker::goToLine |
||
36 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
37 | */ |
||
38 | public function testGoToLineTooHigh() |
||
48 | |||
49 | /** |
||
50 | * @covers TextFile\Walker\SimpleWalker::goToLine |
||
51 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
52 | */ |
||
53 | public function testGoToLineTooLow() |
||
63 | |||
64 | /** |
||
65 | * @covers TextFile\Walker\SimpleWalker::countLines |
||
66 | */ |
||
67 | public function testCountLines() |
||
83 | |||
84 | /** |
||
85 | * @covers TextFile\Walker\SimpleWalker::goBeforeCharacter |
||
86 | */ |
||
87 | public function testGoBeforeCharacter() |
||
107 | |||
108 | /** |
||
109 | * @covers TextFile\Walker\SimpleWalker::goBeforeCharacter |
||
110 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
111 | */ |
||
112 | View Code Duplication | public function testGoBeforeCharacterTooLow() |
|
122 | |||
123 | /** |
||
124 | * @covers TextFile\Walker\SimpleWalker::goBeforeCharacter |
||
125 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
126 | */ |
||
127 | View Code Duplication | public function testGoBeforeCharacterTooHigh() |
|
137 | } |
||
138 |
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.