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