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 Search |
|
16 | { |
||
17 | /** @var TwitchRequest */ |
||
18 | protected $request; |
||
19 | |||
20 | const URI_SEARCH_CHANNELS = 'search/channels'; |
||
21 | const URI_SEARCH_STREAMS = 'search/streams'; |
||
22 | const URI_SEARCH_GAMES = 'search/games'; |
||
23 | |||
24 | /** |
||
25 | * Search constructor |
||
26 | * @param TwitchRequest $request |
||
27 | */ |
||
28 | public function __construct(TwitchRequest $request) |
||
29 | { |
||
30 | $this->request = $request; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Search for channel |
||
35 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/search.md#get-searchchannels |
||
36 | * @param string $queryString |
||
37 | * @return \stdClass |
||
38 | * @throws TwitchSDKException |
||
39 | */ |
||
40 | public function channels($queryString) |
||
44 | |||
45 | /** |
||
46 | * Search streams |
||
47 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/search.md#get-searchstreams |
||
48 | * @param string $queryString |
||
49 | * @return \stdClass |
||
50 | * @throws TwitchSDKException |
||
51 | */ |
||
52 | public function streams($queryString) |
||
53 | { |
||
54 | return $this->request->request(self::URI_SEARCH_STREAMS . $queryString); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Search games |
||
59 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/search.md#get-searchgames |
||
60 | * @param string $queryString |
||
61 | * @return \stdClass |
||
62 | * @throws TwitchSDKException |
||
63 | */ |
||
64 | public function games($queryString) |
||
68 | } |
||
69 |