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 | trait CsvTrait |
||
9 | { |
||
10 | protected static $csvEscapeChar; |
||
11 | |||
12 | /** |
||
13 | * Check whether support the escape_char argument to fgetcsv/fputcsv or not |
||
14 | * |
||
15 | * @return bool |
||
16 | */ |
||
17 | protected static function supportsCsvEscapeChar() |
||
25 | |||
26 | /** |
||
27 | * @param resource $handle |
||
28 | * @param array $options |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | View Code Duplication | protected static function fgetcsv($handle, $options) |
|
40 | |||
41 | /** |
||
42 | * @param resource $handle |
||
43 | * @param array $fields |
||
44 | * @param array $options |
||
45 | * |
||
46 | * @return bool|int |
||
47 | */ |
||
48 | View Code Duplication | protected static function fputcsv($handle, $fields, $options) |
|
56 | } |
||
57 |
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.