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 |
||
8 | class CsvTwigTest extends BaseTwigTest |
||
9 | { |
||
10 | protected static $TEMP_PATH = '/../../tmp/csv/'; |
||
11 | |||
12 | // |
||
13 | // PhpUnit |
||
14 | // |
||
15 | |||
16 | /** |
||
17 | * @return array |
||
18 | */ |
||
19 | public function formatProvider() |
||
20 | { |
||
21 | return [['csv']]; |
||
22 | } |
||
23 | |||
24 | // |
||
25 | // Tests |
||
26 | // |
||
27 | |||
28 | /** |
||
29 | * @param string $format |
||
30 | * |
||
31 | * @throws \Exception |
||
32 | * |
||
33 | * @dataProvider formatProvider |
||
34 | */ |
||
35 | View Code Duplication | public function testBasic($format) |
|
43 | |||
44 | /** |
||
45 | * @param string $format |
||
46 | * |
||
47 | * @throws \Exception |
||
48 | * |
||
49 | * @dataProvider formatProvider |
||
50 | */ |
||
51 | View Code Duplication | public function testDocumentTemplate($format) |
|
59 | } |
||
60 |
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.