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 Subscription |
|
| 16 | { |
||
| 17 | /** @var TwitchRequest */ |
||
| 18 | protected $request; |
||
| 19 | |||
| 20 | const URI_CHANNEL_SUBSCRIPTIONS = 'channels/%s/subscriptions'; |
||
| 21 | const URI_CHANNEL_SUBSCRIPTIONS_USER = 'channels/%s/subscriptions/%s'; |
||
| 22 | const URI_USER_SUBSCRIPTIONS_CHANNEL = 'users/%s/subscriptions/%s'; |
||
| 23 | |||
| 24 | public function __construct(TwitchRequest $request) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @description Returns an array of subscriptions who are subscribed to specified channel |
||
| 31 | * - requires scope 'channel_subscriptions' |
||
| 32 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptions |
||
| 33 | * @param string $channel |
||
| 34 | * @param string $queryString |
||
| 35 | * @return \stdClass |
||
| 36 | * @throws TwitchSDKException |
||
| 37 | */ |
||
| 38 | public function getSubscriptions($channel, $queryString) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns user object if that user is subscribed |
||
| 45 | * - requires scope 'channel_check_subscription' for channel |
||
| 46 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptionsuser |
||
| 47 | * @param string $channel |
||
| 48 | * @param string $user |
||
| 49 | * @param string $queryString |
||
| 50 | * @return \stdClass |
||
| 51 | * @throws TwitchSDKException |
||
| 52 | */ |
||
| 53 | public function getSubscribedUser($channel, $user, $queryString) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns a channel object that user subscribes to |
||
| 60 | * - requires scope 'user_subscriptions' for user |
||
| 61 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-usersusersubscriptionschannel |
||
| 62 | * @param string $user |
||
| 63 | * @param string $channel |
||
| 64 | * @param string $queryString |
||
| 65 | * @return \stdClass |
||
| 66 | * @throws TwitchSDKException |
||
| 67 | */ |
||
| 68 | public function getSubscribedToChannel($user, $channel, $queryString) |
||
| 72 | } |
||
| 73 |