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 |
||
17 | View Code Duplication | class Chat |
|
1 ignored issue
–
show
|
|||
18 | { |
||
19 | /** @var TwitchRequest */ |
||
20 | protected $request; |
||
21 | |||
22 | const URI_CHAT = 'chat/'; |
||
23 | const URI_CHAT_EMOTICONS = 'chat/emoticons'; |
||
24 | const URI_CHAT_EMOTICONS_IMAGES = 'chat/emoticon_images'; |
||
25 | const URI_CHAT_BADGES = 'chat/%s/badges'; |
||
26 | |||
27 | /** |
||
28 | * Chat constructor |
||
29 | * @param TwitchRequest $request |
||
30 | */ |
||
31 | public function __construct(TwitchRequest $request) |
||
35 | |||
36 | /** |
||
37 | * Returns a links object to all other chat endpoints |
||
38 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md#get-chatchannel |
||
39 | * @param string $channel |
||
40 | * @return \stdClass |
||
41 | * @throws TwitchException |
||
42 | */ |
||
43 | public function getChat($channel) |
||
49 | |||
50 | /** |
||
51 | * Get a chat's emoticons |
||
52 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md#get-chatemoticons |
||
53 | * @return \stdClass |
||
54 | * @throws TwitchException |
||
55 | */ |
||
56 | public function getEmoticons() |
||
62 | |||
63 | /** |
||
64 | * Returns a list of emoticons |
||
65 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md#get-chatemoticon_images |
||
66 | * @param string $queryString |
||
67 | * @return \stdClass |
||
68 | * @throws TwitchException |
||
69 | */ |
||
70 | public function getEmoticonImages($queryString) |
||
76 | |||
77 | /** |
||
78 | * Returns a list of chat badges that can be used in the :channel's chat |
||
79 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md#get-chatchannelbadges |
||
80 | * @param string $channel |
||
81 | * @return \stdClass |
||
82 | * @throws TwitchException |
||
83 | */ |
||
84 | public function getBadges($channel) |
||
90 | } |
||
91 |
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.