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 Stream |
|
16 | { |
||
17 | /** @var TwitchRequest */ |
||
18 | protected $request; |
||
19 | |||
20 | const URI_STREAM = 'streams/'; |
||
21 | const URI_STREAMS = 'streams'; |
||
22 | const URI_STREAMS_FEATURED = 'streams/featured'; |
||
23 | const URI_STREAM_SUMMARY = 'streams/summary'; |
||
24 | |||
25 | /** |
||
26 | * Stream constructor |
||
27 | * @param TwitchRequest $request |
||
28 | */ |
||
29 | public function __construct(TwitchRequest $request) |
||
33 | |||
34 | /** |
||
35 | * Get the specified channel's stream |
||
36 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamschannel |
||
37 | * @param string $channel |
||
38 | * @return \stdClass |
||
39 | * @throws TwitchSDKException |
||
40 | */ |
||
41 | public function getStream($channel) |
||
45 | |||
46 | /** |
||
47 | * Returns a list of streams |
||
48 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streams |
||
49 | * @param string $queryString |
||
50 | * @return \stdClass |
||
51 | * @throws TwitchSDKException |
||
52 | */ |
||
53 | public function getStreams($queryString) |
||
57 | |||
58 | /** |
||
59 | * Returns a list of featured (promoted) stream |
||
60 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamsfeatured |
||
61 | * @param string $queryString |
||
62 | * @return \stdClass |
||
63 | * @throws TwitchSDKException |
||
64 | */ |
||
65 | public function getFeatured($queryString) |
||
69 | |||
70 | /** |
||
71 | * Returns a summary of current streams |
||
72 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamssummary |
||
73 | * @param string $queryString |
||
74 | * @return \stdClass |
||
75 | * @throws TwitchSDKException |
||
76 | */ |
||
77 | public function getSummary($queryString) |
||
81 | } |
||
82 |