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 |
||
21 | View Code Duplication | class MetadataModel extends AbstractModel implements ResourceModelInterface |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * Key should be less than 50 symbols and match following regular expression ([A-Za-z0-9_-]+). |
||
25 | * |
||
26 | * @SA\Type("string") |
||
27 | * @SA\SerializedName("key") |
||
28 | * |
||
29 | * @var string|null |
||
30 | */ |
||
31 | protected $key; |
||
32 | |||
33 | /** |
||
34 | * Value should be less than 1000 symbols, compatible with JSON string. |
||
35 | * Use JSON 'null' in order to remove metadata entry. |
||
36 | * |
||
37 | * @SA\Type("string") |
||
38 | * @SA\SerializedName("value") |
||
39 | * |
||
40 | * @var string|null |
||
41 | */ |
||
42 | protected $value; |
||
43 | |||
44 | /** |
||
45 | * @return null|string |
||
46 | */ |
||
47 | 1 | public function getKey() |
|
51 | |||
52 | /** |
||
53 | * @param null|string $key |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | 1 | public function setKey($key) |
|
63 | |||
64 | /** |
||
65 | * @return null|string |
||
66 | */ |
||
67 | 1 | public function getValue() |
|
71 | |||
72 | /** |
||
73 | * @param null|string $value |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | 1 | public function setValue($value) |
|
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.