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); |
||
18 | class OpenStack |
||
19 | { |
||
20 | /** @var Builder */ |
||
21 | private $builder; |
||
22 | |||
23 | /** |
||
24 | * @param array $options User-defined options |
||
25 | * |
||
26 | * $options['username'] = (string) Your OpenStack username [REQUIRED] |
||
27 | * ['password'] = (string) Your OpenStack password [REQUIRED] |
||
28 | 7 | * ['tenantId'] = (string) Your tenant ID [REQUIRED if tenantName omitted] |
|
29 | * ['tenantName'] = (string) Your tenant name [REQUIRED if tenantId omitted] |
||
30 | 7 | * ['authUrl'] = (string) The Keystone URL [REQUIRED] |
|
31 | 7 | * ['debugLog'] = (bool) Whether to enable HTTP logging [OPTIONAL] |
|
32 | * ['logger'] = (LoggerInterface) Must set if debugLog is true [OPTIONAL] |
||
33 | * ['messageFormatter'] = (MessageFormatter) Must set if debugLog is true [OPTIONAL] |
||
34 | * ['requestOptions'] = (array) Guzzle Http request options [OPTIONAL] |
||
35 | * |
||
36 | * @param Builder $builder |
||
37 | */ |
||
38 | public function __construct(array $options = [], Builder $builder = null) |
||
46 | |||
47 | /** |
||
48 | * @param array $options |
||
49 | * |
||
50 | * @return Service |
||
51 | */ |
||
52 | private function getDefaultIdentityService(array $options): Service |
||
78 | |||
79 | 1 | /** |
|
80 | * Creates a new Compute v2 service. |
||
81 | 1 | * |
|
82 | 1 | * @param array $options Options that will be used in configuring the service. |
|
83 | * |
||
84 | * @return \OpenStack\Compute\v2\Service |
||
85 | */ |
||
86 | public function computeV2(array $options = []): \OpenStack\Compute\v2\Service |
||
91 | |||
92 | 1 | /** |
|
93 | * Creates a new Networking v2 service. |
||
94 | 1 | * |
|
95 | 1 | * @param array $options Options that will be used in configuring the service. |
|
96 | * |
||
97 | * @return \OpenStack\Networking\v2\Service |
||
98 | */ |
||
99 | public function networkingV2(array $options = []): \OpenStack\Networking\v2\Service |
||
104 | |||
105 | 1 | /** |
|
106 | * Creates a new Networking v2 Layer 3 service. |
||
107 | 1 | * |
|
108 | 1 | * @param array $options Options that will be used in configuring the service. |
|
109 | * |
||
110 | * @return \OpenStack\Networking\v2\Extensions\Layer3\Service |
||
111 | */ |
||
112 | public function networkingV2ExtLayer3(array $options = []): \OpenStack\Networking\v2\Extensions\Layer3\Service |
||
117 | |||
118 | 1 | /** |
|
119 | * Creates a new Networking v2 Layer 3 service. |
||
120 | 1 | * |
|
121 | 1 | * @param array $options Options that will be used in configuring the service. |
|
122 | * |
||
123 | * @return \OpenStack\Networking\v2\Extensions\SecurityGroups\Service |
||
124 | */ |
||
125 | public function networkingV2ExtSecGroups(array $options = []): \OpenStack\Networking\v2\Extensions\SecurityGroups\Service |
||
130 | |||
131 | /** |
||
132 | * Creates a new Identity v2 service. |
||
133 | * |
||
134 | * @param array $options Options that will be used in configuring the service. |
||
135 | * |
||
136 | * @return \OpenStack\Identity\v2\Service |
||
137 | */ |
||
138 | public function identityV2(array $options = []): \OpenStack\Identity\v2\Service |
||
143 | |||
144 | /** |
||
145 | * Creates a new Identity v3 service. |
||
146 | * |
||
147 | * @param array $options Options that will be used in configuring the service. |
||
148 | * |
||
149 | * @return \OpenStack\Identity\v3\Service |
||
150 | */ |
||
151 | public function identityV3(array $options = []): \OpenStack\Identity\v3\Service |
||
156 | |||
157 | /** |
||
158 | * Creates a new Object Store v1 service. |
||
159 | * |
||
160 | * @param array $options Options that will be used in configuring the service. |
||
161 | * |
||
162 | * @return \OpenStack\ObjectStore\v1\Service |
||
163 | */ |
||
164 | public function objectStoreV1(array $options = []): \OpenStack\ObjectStore\v1\Service |
||
169 | |||
170 | /** |
||
171 | * Creates a new Block Storage v2 service. |
||
172 | * |
||
173 | * @param array $options Options that will be used in configuring the service. |
||
174 | * |
||
175 | * @return \OpenStack\BlockStorage\v2\Service |
||
176 | */ |
||
177 | public function blockStorageV2(array $options = []): \OpenStack\BlockStorage\v2\Service |
||
182 | |||
183 | /** |
||
184 | * Creates a new Images v2 service. |
||
185 | * |
||
186 | * @param array $options Options that will be used in configuring the service. |
||
187 | * |
||
188 | * @return \OpenStack\Images\v2\Service |
||
189 | */ |
||
190 | public function imagesV2(array $options = []): \OpenStack\Images\v2\Service |
||
195 | |||
196 | /** |
||
197 | * Creates a new Gnocchi Metric service v1 |
||
198 | * |
||
199 | * @param array $options |
||
200 | * |
||
201 | * @return \OpenStack\Metric\v1\Gnocchi\Service |
||
202 | */ |
||
203 | public function metricGnocchiV1(array $options = []): \OpenStack\Metric\v1\Gnocchi\Service |
||
209 | } |
||
210 |
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.