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 |
||
7 | class Webspace extends \PleskX\Api\Operator |
||
8 | { |
||
9 | |||
10 | public function getPermissionDescriptor() |
||
15 | |||
16 | public function getLimitDescriptor() |
||
21 | |||
22 | public function getPhysicalHostingDescriptor() |
||
27 | |||
28 | /** |
||
29 | * @param string $field |
||
30 | * @param integer|string $value |
||
31 | * @return Struct\PhpSettings |
||
32 | */ |
||
33 | View Code Duplication | public function getPhpSettings($field, $value) |
|
45 | |||
46 | /** |
||
47 | * @param string $field |
||
48 | * @param integer|string $value |
||
49 | * @return Struct\Limits |
||
50 | */ |
||
51 | public function getLimits($field, $value) |
||
56 | |||
57 | /** |
||
58 | * @param array $properties |
||
59 | * @param array|null $hostingProperties |
||
60 | * @param $planName |
||
61 | * @return Struct\Info |
||
62 | */ |
||
63 | public function create(array $properties, array $hostingProperties = null, $planName = null) |
||
93 | |||
94 | /** |
||
95 | * @param string $field |
||
96 | * @param integer|string $value |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function delete($field, $value) |
||
103 | |||
104 | /** |
||
105 | * @param string $field |
||
106 | * @param integer|string $value |
||
107 | * @return Struct\GeneralInfo |
||
108 | */ |
||
109 | public function get($field, $value) |
||
114 | |||
115 | /** |
||
116 | * @return Struct\GeneralInfo[] |
||
117 | */ |
||
118 | public function getAll() |
||
122 | |||
123 | /** |
||
124 | * @param string $field |
||
125 | * @param integer|string $value |
||
126 | * @return Struct\DiskUsage |
||
127 | */ |
||
128 | public function getDiskUsage($field, $value) |
||
133 | } |
||
134 |
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.