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 |
||
14 | class AccountService implements AccountServiceInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var \linkprofit\AmoCRM\RequestHandler |
||
18 | */ |
||
19 | protected $request; |
||
20 | |||
21 | /** |
||
22 | * ServiceInterface constructor. |
||
23 | * |
||
24 | * @param RequestHandler $requestHandler |
||
25 | */ |
||
26 | 4 | public function __construct(RequestHandler $requestHandler) |
|
30 | |||
31 | /** |
||
32 | * @return bool|array |
||
33 | */ |
||
34 | 1 | public function getAllArray() |
|
40 | |||
41 | /** |
||
42 | * @return array|bool|\linkprofit\AmoCRM\entities\Account |
||
43 | */ |
||
44 | 1 | public function getAccount() |
|
50 | |||
51 | /** |
||
52 | * TODO |
||
53 | * |
||
54 | * @return \linkprofit\AmoCRM\entities\Field[] |
||
55 | */ |
||
56 | 1 | public function getCustomFields() |
|
62 | |||
63 | /** |
||
64 | * TODO |
||
65 | * |
||
66 | * @return \linkprofit\AmoCRM\entities\User[] |
||
67 | */ |
||
68 | public function getUsers() {} |
||
69 | |||
70 | /** |
||
71 | * TODO |
||
72 | * |
||
73 | * @return \linkprofit\AmoCRM\entities\Pipeline[] |
||
74 | */ |
||
75 | public function getPipelines() {} |
||
76 | |||
77 | /** |
||
78 | * TODO |
||
79 | * |
||
80 | * @return \linkprofit\AmoCRM\entities\Group[] |
||
81 | */ |
||
82 | public function getGroups() {} |
||
83 | |||
84 | /** |
||
85 | * TODO |
||
86 | * |
||
87 | * @return \linkprofit\AmoCRM\entities\NoteTypes[] |
||
88 | */ |
||
89 | public function getNoteTypes() {} |
||
90 | |||
91 | /** |
||
92 | * @return \linkprofit\AmoCRM\entities\TaskType[] |
||
93 | */ |
||
94 | 1 | public function getTaskTypes() |
|
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | 4 | protected function getLink() |
|
108 | |||
109 | /** |
||
110 | * @param array $with |
||
111 | */ |
||
112 | 4 | private function send($with = ['with' => 'custom_fields,users,pipelines,groups,note_types,task_types']) |
|
117 | |||
118 | /** |
||
119 | * @param $array |
||
120 | * |
||
121 | * @return Account |
||
122 | */ |
||
123 | 1 | private function parseArrayToAccountEntity($array) |
|
130 | |||
131 | /** |
||
132 | * @param array $array |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | 1 | public function parseArrayToTaskTypeEntities(array $array) |
|
148 | |||
149 | /** |
||
150 | * @param array $array |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | 1 | private function parseCustomFieldsArrayToFieldEntities(array $array) |
|
183 | |||
184 | /** |
||
185 | * @param array $items |
||
186 | * @param int $elementType |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | 1 | private function parseArrayToFieldEntities(array $items, $elementType) |
|
199 | |||
200 | /** |
||
201 | * @param array $item |
||
202 | * @param $elementType |
||
203 | * |
||
204 | * @return \linkprofit\AmoCRM\entities\Field |
||
205 | */ |
||
206 | 1 | private function parseArrayToFieldEntity(array $item, $elementType) |
|
214 | |||
215 | /** |
||
216 | * @param array $items |
||
217 | * |
||
218 | * @return array |
||
219 | */ |
||
220 | 1 | private function parseArrayToCatalogFieldEntities(array $items) |
|
228 | } |
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.