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 |
||
15 | View Code Duplication | class User |
|
16 | { |
||
17 | /** @var TwitchRequest */ |
||
18 | protected $request; |
||
19 | |||
20 | const URI_USER = 'users/'; |
||
21 | const URI_USER_AUTH = 'user'; |
||
22 | const URI_STREAMS_FOLLOWED_AUTH = 'streams/followed'; |
||
23 | const URI_VIDEOS_FOLLOWED_AUTH = 'videos/followed'; |
||
24 | |||
25 | public function __construct(TwitchRequest $request) |
||
29 | |||
30 | /** |
||
31 | * Get the specified user |
||
32 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-usersuser |
||
33 | * @param string $username |
||
34 | * @return \stdClass |
||
35 | * @throws TwitchSDKException |
||
36 | */ |
||
37 | public function getUser($username) |
||
41 | |||
42 | /** |
||
43 | * Get the authenticated user |
||
44 | * - requires scope 'user_read' |
||
45 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-user |
||
46 | * @param string $queryString |
||
47 | * @return \stdClass |
||
48 | * @throws TwitchSDKException |
||
49 | */ |
||
50 | public function getUserAuth($queryString) |
||
54 | |||
55 | /** |
||
56 | * List the live streams that the authenticated user is following |
||
57 | * - requires scope 'user_read' |
||
58 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-streamsfollowed |
||
59 | * @param string $queryString |
||
60 | * @return \stdClass |
||
61 | * @throws TwitchSDKException |
||
62 | */ |
||
63 | public function getFollowedStreams($queryString) |
||
67 | |||
68 | /** |
||
69 | * List of videos that the authenticated user is following |
||
70 | * - requires scope 'user_read' |
||
71 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-videosfollowed |
||
72 | * @param string $queryString |
||
73 | * @return \stdClass |
||
74 | * @throws TwitchSDKException |
||
75 | */ |
||
76 | public function getFollowedVideos($queryString) |
||
80 | } |
||
81 |