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 declare(strict_types=1); |
||
17 | View Code Duplication | class LoadBalancerHealthMonitor extends OperatorResource implements Creatable, Retrievable, Updateable, Deletable |
|
|
|||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | public $id; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | public $tenantId; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | public $type; |
||
33 | |||
34 | /** |
||
35 | * @var integer |
||
36 | */ |
||
37 | public $delay; |
||
38 | |||
39 | /** |
||
40 | * @var integer |
||
41 | */ |
||
42 | public $timeout; |
||
43 | |||
44 | /** |
||
45 | * @var integer |
||
46 | */ |
||
47 | public $maxRetries; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | public $httpMethod; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | public $urlPath; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | public $expectedCodes; |
||
63 | |||
64 | /** |
||
65 | * @var boolean |
||
66 | */ |
||
67 | public $adminStateUp; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | */ |
||
72 | public $poolId; |
||
73 | |||
74 | /** |
||
75 | * @var LoadBalancerPool[] |
||
76 | */ |
||
77 | public $pools; |
||
78 | |||
79 | /** |
||
80 | * @var string |
||
81 | */ |
||
82 | public $operatingStatus; |
||
83 | |||
84 | /** |
||
85 | * @var string |
||
86 | */ |
||
87 | public $provisioningStatus; |
||
88 | |||
89 | protected $resourcesKey = 'healthmonitors'; |
||
90 | protected $resourceKey = 'healthmonitor'; |
||
91 | |||
92 | protected $aliases = [ |
||
93 | 'tenant_id' => 'tenantId', |
||
94 | 'admin_state_up' => 'adminStateUp', |
||
95 | 'max_retries' => 'maxRetries', |
||
96 | 'http_method' => 'httpMethod', |
||
97 | 'url_path' => 'urlPath', |
||
98 | 'expected_codes' => 'expectedCodes', |
||
99 | 'pool_id' => 'poolId', |
||
100 | 'operating_status' => 'operatingStatus', |
||
101 | 'provisioning_status' => 'provisioningStatus' |
||
102 | ]; |
||
103 | |||
104 | /** |
||
105 | * {@inheritDoc} |
||
106 | */ |
||
107 | public function create(array $userOptions): Creatable |
||
112 | |||
113 | /** |
||
114 | * {@inheritDoc} |
||
115 | */ |
||
116 | public function retrieve() |
||
121 | |||
122 | /** |
||
123 | * {@inheritDoc} |
||
124 | */ |
||
125 | public function update() |
||
130 | |||
131 | /** |
||
132 | * {@inheritDoc} |
||
133 | */ |
||
134 | public function delete() |
||
138 | } |
||
139 |
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.