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 |
||
14 | class SimpleReaderTest extends TextFileTestCase |
||
15 | { |
||
16 | /** |
||
17 | * @covers TextFile\Reader\SimpleReader::getLinesRange |
||
18 | */ |
||
19 | public function testGetLinesRange() |
||
31 | |||
32 | /** |
||
33 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
34 | */ |
||
35 | public function testGetNextLineContentFromStart() |
||
48 | |||
49 | /** |
||
50 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
51 | */ |
||
52 | public function testGetNextLineContent() |
||
67 | |||
68 | /** |
||
69 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
70 | * |
||
71 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
72 | */ |
||
73 | View Code Duplication | public function testGetNextLineContentOutOfBounds() |
|
84 | |||
85 | /** |
||
86 | * @covers TextFile\Reader\SimpleReader::getPreviousLineContent |
||
87 | */ |
||
88 | public function testGetPreviousLineContent() |
||
103 | |||
104 | /** |
||
105 | * @covers TextFile\Reader\SimpleReader::getPreviousLineContent |
||
106 | * |
||
107 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
108 | */ |
||
109 | View Code Duplication | public function testGetPreviousLineContentOutOfBounds() |
|
120 | |||
121 | /** |
||
122 | * @covers TextFile\Reader\SimpleReader::getCurrentLineContent |
||
123 | */ |
||
124 | public function testGetCurrentLineContent() |
||
139 | |||
140 | /** |
||
141 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
142 | */ |
||
143 | public function testGetLineContent() |
||
152 | |||
153 | /** |
||
154 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
155 | * |
||
156 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
157 | */ |
||
158 | public function testGetLineContentOutOfBoundsTooHigh() |
||
167 | |||
168 | /** |
||
169 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
170 | * |
||
171 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
172 | */ |
||
173 | public function testGetLineContentOutOfBoundsTooLow() |
||
182 | |||
183 | /** |
||
184 | * @covers TextFile\Reader\SimpleReader::getNextCharacterContent |
||
185 | */ |
||
186 | public function testGetNextCharacterContent() |
||
197 | |||
198 | /** |
||
199 | * @covers TextFile\Reader\SimpleReader::getPreviousCharacterContent |
||
200 | */ |
||
201 | public function testGetPreviousCharacterContent() |
||
212 | |||
213 | /** |
||
214 | * @covers TextFile\Reader\SimpleReader::getCharacterContent |
||
215 | */ |
||
216 | public function testGetCharacterContent() |
||
225 | |||
226 | /** |
||
227 | * @covers TextFile\Reader\SimpleReader::getPreviousCharacterContent |
||
228 | */ |
||
229 | public function testCleanLineContent() |
||
235 | } |
||
236 |
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.