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 |
||
| 26 | class PgHstore extends ArrayTypeConverter |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @see \Pomm\Converter\ConverterInterface |
||
| 30 | */ |
||
| 31 | public function fromPg($data, $type, Session $session) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @see \Pomm\Converter\ConverterInterface |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function toPg($data, $type, Session $session) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @see \Pomm\Converter\ConverterInterface |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function toPgStandardFormat($data, $type, Session $session) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * buildArray |
||
| 73 | * |
||
| 74 | * Return an array of HStore elements. |
||
| 75 | * |
||
| 76 | * @param array $data |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | protected function buildArray(array $data) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * escape |
||
| 100 | * |
||
| 101 | * Escape a string. |
||
| 102 | * |
||
| 103 | * @param string $string |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | protected function escape($string) |
||
| 114 | } |
||
| 115 |
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.