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 |
||
| 4 | trait DumpTrait |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * Convert the object into json |
||
| 8 | * |
||
| 9 | * @return array |
||
| 10 | */ |
||
| 11 | View Code Duplication | public function jsonSerialize() |
|
| 21 | |||
| 22 | /** |
||
| 23 | * Dump object to array |
||
| 24 | * |
||
| 25 | * @return array |
||
| 26 | */ |
||
| 27 | public function __toArray() |
||
| 31 | |||
| 32 | public function __toXML() |
||
| 43 | |||
| 44 | protected function composeXML($data, &$xml) |
||
| 59 | } |
||
| 60 |