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 |
||
24 | View Code Duplication | final class Property |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Field type. |
||
28 | * |
||
29 | * @var string |
||
30 | * |
||
31 | * @Required |
||
32 | * @Enum({"string", "boolean", "integer", "float", "long", "short", "byte", "double", "date", |
||
33 | * "geo_point", "geo_shape", "ip", "binary", "token_count" }) |
||
34 | */ |
||
35 | public $type; |
||
36 | |||
37 | /** |
||
38 | * Name of the type field. Defaults to normalized property name. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | public $name; |
||
43 | |||
44 | /** |
||
45 | * In this field you can define options (like analyzers and etc) for specific field types. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | public $options; |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function dump(array $exclude = []) |
||
76 | } |
||
77 |
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.