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 ProtectedDirectory extends \PleskX\Api\Operator |
||
9 | { |
||
10 | protected $_wrapperTag = 'protected-dir'; |
||
11 | |||
12 | /** |
||
13 | * @param string $name |
||
14 | * @param int $siteId |
||
15 | * @param string $header |
||
16 | * |
||
17 | * @return Struct\Info |
||
18 | */ |
||
19 | View Code Duplication | public function add($name, $siteId, $header = '') |
|
30 | |||
31 | /** |
||
32 | * @param string $field |
||
33 | * @param int|string $value |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | public function delete($field, $value) |
||
41 | |||
42 | /** |
||
43 | * @param string $field |
||
44 | * @param int|string $value |
||
45 | * |
||
46 | * @return Struct\DataInfo|false |
||
47 | */ |
||
48 | public function get($field, $value) |
||
54 | |||
55 | /** |
||
56 | * @param string $field |
||
57 | * @param int|string $value |
||
58 | * |
||
59 | * @return Struct\DataInfo[] |
||
60 | */ |
||
61 | View Code Duplication | public function getAll($field, $value) |
|
71 | |||
72 | /** |
||
73 | * @param Struct\Info $protectedDirectory |
||
74 | * @param string $login |
||
75 | * @param string $password |
||
76 | * |
||
77 | * @return Struct\UserInfo |
||
78 | */ |
||
79 | View Code Duplication | public function addUser($protectedDirectory, $login, $password) |
|
90 | |||
91 | /** |
||
92 | * @param string $field |
||
93 | * @param int|string $value |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function deleteUser($field, $value) |
||
101 | |||
102 | /** |
||
103 | * @param $command |
||
104 | * @param $field |
||
105 | * @param $value |
||
106 | * |
||
107 | * @return \PleskX\Api\XmlResponse |
||
108 | */ |
||
109 | View Code Duplication | private function _get($command, $field, $value) |
|
123 | } |
||
124 |
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.