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 |
||
| 7 | class Car |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @Serializer\SerializedName("super_model") |
||
| 11 | */ |
||
| 12 | private $model; |
||
| 13 | |||
| 14 | private $carSize; |
||
| 15 | |||
| 16 | private $color; |
||
| 17 | |||
| 18 | public function __construct($withValues = false) |
||
| 19 | { |
||
| 20 | if ($withValues) { |
||
| 21 | $this->model = 'val_model'; |
||
| 22 | $this->carSize = 'val_size'; |
||
| 23 | $this->color = 'val_color'; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | } |
||
| 27 |