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 |
||
8 | class ServicePlan extends \PleskX\Api\Operator |
||
9 | { |
||
10 | /** |
||
11 | * @param array $properties |
||
12 | * @return Struct\Info |
||
13 | */ |
||
14 | public function create($properties) |
||
19 | |||
20 | /** |
||
21 | * @param string $field |
||
22 | * @param int|string $value |
||
23 | * @return bool |
||
24 | */ |
||
25 | public function delete($field, $value) |
||
29 | |||
30 | /** |
||
31 | * @param string $field |
||
32 | * @param int|string $value |
||
33 | * |
||
34 | * @return Struct\Info |
||
35 | */ |
||
36 | public function get($field, $value) |
||
42 | |||
43 | /** |
||
44 | * @return Struct\Info[] |
||
45 | */ |
||
46 | public function getAll() |
||
50 | |||
51 | /** |
||
52 | * @param string|null $field |
||
53 | * @param int|string|null $value |
||
54 | * |
||
55 | * @return Struct\Info|Struct\Info[] |
||
56 | */ |
||
57 | View Code Duplication | private function _get($field = null, $value = null) |
|
76 | } |
||
77 |
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.