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 |
|
1 ignored issue
–
show
|
|||
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 TwitchException |
||
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 TwitchException |
||
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 TwitchException |
||
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 TwitchException |
||
76 | */ |
||
77 | public function getSummary($queryString) |
||
81 | } |
||
82 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.