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 |
||
| 17 | class NewsItem extends Message |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Messages type. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $type = 'news'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Properties. |
||
| 28 | * |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected $properties = [ |
||
| 32 | 'title', |
||
| 33 | 'description', |
||
| 34 | 'url', |
||
| 35 | 'image', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | View Code Duplication | public function toJsonArray() |
|
| 47 | |||
| 48 | View Code Duplication | public function toXmlArray() |
|
| 57 | } |
||
| 58 |