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 |
||
13 | View Code Duplication | class KickChatMember extends AbstractMethod |
|
|
|||
14 | { |
||
15 | const NAME = 'kickChatMember'; |
||
16 | |||
17 | const RETURN_ENTITY = null; |
||
18 | |||
19 | protected $chat_id; |
||
20 | |||
21 | protected $user_id; |
||
22 | |||
23 | protected $supportedProperties = [ |
||
24 | 'chat_id' => true, |
||
25 | 'user_id' => true |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function getChatId() |
||
35 | |||
36 | /** |
||
37 | * @param mixed $chat_id |
||
38 | * |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function setChatId($chat_id) |
||
47 | |||
48 | /** |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function getUserId() |
||
55 | |||
56 | /** |
||
57 | * @param mixed $user_id |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function setUserId($user_id) |
||
67 | } |
||
68 |
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.