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 GroupResponseModel extends AbstractModel implements ResponseModelInterface |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * Kind of response. |
||
25 | * |
||
26 | * @SA\Type("string") |
||
27 | * @SA\SerializedName("kind") |
||
28 | * |
||
29 | * @var string|null |
||
30 | */ |
||
31 | protected $kind; |
||
32 | |||
33 | /** |
||
34 | * Collection of response models. |
||
35 | * |
||
36 | * @SA\Type("array<Zibios\WrikePhpJmsserializer\Model\Group\GroupResourceModel>") |
||
37 | * @SA\SerializedName("data") |
||
38 | * |
||
39 | * @var array|GroupResourceModel]|null |
||
40 | */ |
||
41 | protected $data; |
||
42 | |||
43 | /** |
||
44 | * @return array|null|GroupResourceModel[] |
||
45 | */ |
||
46 | 3 | public function getData() |
|
50 | |||
51 | /** |
||
52 | * @param array|null|GroupResourceModel[] $data |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | 1 | public function setData($data) |
|
62 | |||
63 | /** |
||
64 | * @return null|string |
||
65 | */ |
||
66 | 1 | public function getKind() |
|
70 | |||
71 | /** |
||
72 | * @param null|string $kind |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | 1 | public function setKind($kind) |
|
82 | } |
||
83 |
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.