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 |
||
23 | View Code Duplication | final class Embedded |
|
|
|||
24 | { |
||
25 | /** |
||
26 | * Inner object class name. |
||
27 | * |
||
28 | * @var string Object name to map |
||
29 | * |
||
30 | * @Required |
||
31 | */ |
||
32 | public $class; |
||
33 | |||
34 | /** |
||
35 | * Name of the type field. Defaults to normalized property name. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | public $name; |
||
40 | |||
41 | /** |
||
42 | * Defines if related object will have one or multiple values. |
||
43 | * |
||
44 | * If this value is set to true, in the result ObjectIterator will be provided, |
||
45 | * otherwise you will get single object. |
||
46 | * |
||
47 | * @var bool Object or ObjectIterator |
||
48 | */ |
||
49 | public $multiple; |
||
50 | |||
51 | /** |
||
52 | * In this field you can define options. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | public $options; |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function dump(array $exclude = []) |
||
83 | } |
||
84 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.