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 DnsTemplate extends \PleskX\Api\Operator |
||
9 | { |
||
10 | protected $_wrapperTag = 'dns'; |
||
11 | |||
12 | /** |
||
13 | * @param array $properties |
||
14 | * |
||
15 | * @return Struct\Info |
||
16 | */ |
||
17 | View Code Duplication | public function create(array $properties) |
|
29 | |||
30 | /** |
||
31 | * @param string $field |
||
32 | * @param int|string $value |
||
33 | * |
||
34 | * @return Struct\Info|null |
||
35 | */ |
||
36 | public function get($field, $value) |
||
42 | |||
43 | /** |
||
44 | * @param string $field |
||
45 | * @param int|string $value |
||
46 | * |
||
47 | * @return Struct\Info[] |
||
48 | */ |
||
49 | View Code Duplication | public function getAll($field = null, $value = null) |
|
70 | |||
71 | /** |
||
72 | * @param string $field |
||
73 | * @param int|string $value |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function delete($field, $value) |
||
88 | } |
||
89 |
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.