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