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 Video |
|
| 16 | { |
||
| 17 | /** @var TwitchRequest */ |
||
| 18 | protected $request; |
||
| 19 | |||
| 20 | const URI_VIDEO = 'videos/'; |
||
| 21 | const URI_VIDEO_TOP = 'videos/top'; |
||
| 22 | const URI_VIDEO_CHANNEL = 'channels/%s/videos'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Video constructor |
||
| 26 | * @param TwitchRequest $request |
||
| 27 | */ |
||
| 28 | public function __construct(TwitchRequest $request) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Returns a video object |
||
| 35 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-videosid |
||
| 36 | * @param string $id |
||
| 37 | * @return \stdClass |
||
| 38 | * @throws TwitchSDKException |
||
| 39 | */ |
||
| 40 | public function getVideo($id) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Returns a list of videos created in a given time period sorted by number of views, most popular first |
||
| 47 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-videostop |
||
| 48 | * @param string $queryString |
||
| 49 | * @return \stdClass |
||
| 50 | * @throws TwitchSDKException |
||
| 51 | */ |
||
| 52 | public function getTop($queryString) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Returns a list of videos ordered by time of creation, starting with the most recent from :channel |
||
| 59 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos |
||
| 60 | * @param string $channel |
||
| 61 | * @param string $queryString |
||
| 62 | * @return \stdClass |
||
| 63 | * @throws TwitchSDKException |
||
| 64 | */ |
||
| 65 | public function getChannelVideos($channel, $queryString) |
||
| 69 | } |
||
| 70 |