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