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 | trait DeleteTrait |
||
22 | { |
||
23 | abstract protected function uri($uri); |
||
24 | |||
25 | abstract protected function request($method, $uri, $options); |
||
26 | |||
27 | /** |
||
28 | * Delete an API key |
||
29 | * |
||
30 | * @param string $key API key |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | View Code Duplication | public function deleteApiKey($key) |
|
54 | 9 | ||
55 | /** |
||
56 | 9 | * Delete a template in template storage |
|
57 | * |
||
58 | * @param string $templateName Template name |
||
59 | * |
||
60 | * @throws InvalidArgumentException |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | View Code Duplication | public function deleteTemplate($templateName) |
|
84 | } |
||
85 |
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.