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 |
||
25 | class PgInterval implements ConverterInterface |
||
26 | { |
||
27 | /** |
||
28 | * @see ConverterInterface |
||
29 | */ |
||
30 | public function fromPg($data, $type, Session $session) |
||
46 | |||
47 | /** |
||
48 | * @see ConverterInterface |
||
49 | */ |
||
50 | View Code Duplication | public function toPg($data, $type, Session $session) |
|
57 | |||
58 | |||
59 | /** |
||
60 | * @see ConverterInterface |
||
61 | */ |
||
62 | View Code Duplication | public function toPgStandardFormat($data, $type, Session $session) |
|
69 | |||
70 | /** |
||
71 | * checkData |
||
72 | * |
||
73 | * Check if Data is a DateInterval. If not, it tries to instantiate a |
||
74 | * DateInterval with the given data. |
||
75 | * |
||
76 | * @param mixed $data |
||
77 | * @throws ConverterException |
||
78 | * @return \DateInterval $data |
||
79 | */ |
||
80 | View Code Duplication | protected function checkData($data) |
|
92 | } |
||
93 |
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.