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 Block |
|
16 | { |
||
17 | /** @var TwitchRequest */ |
||
18 | protected $request; |
||
19 | |||
20 | const URI_BLOCK_USER = 'users/%s/blocks'; |
||
21 | const URI_BLOCK_TARGET = 'users/%s/blocks/%s'; |
||
22 | |||
23 | /** |
||
24 | * Block constructor |
||
25 | * @param TwitchRequest $request |
||
26 | */ |
||
27 | public function __construct(TwitchRequest $request) |
||
31 | |||
32 | /** |
||
33 | * Returns a list of blocks |
||
34 | * - requires scope 'user_blocks_read' |
||
35 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#get-usersuserblocks |
||
36 | * @param string $user |
||
37 | * @param string $queryString |
||
38 | * @return \stdClass |
||
39 | * @throws TwitchSDKException |
||
40 | */ |
||
41 | public function getBlocks($user, $queryString) |
||
45 | |||
46 | /** |
||
47 | * Adds $target to $user block list |
||
48 | * - requires scope 'user_blocks_edit' |
||
49 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#put-usersuserblockstarget |
||
50 | * @param string $user |
||
51 | * @param string $target |
||
52 | * @param string $queryString |
||
53 | * @return \stdClass |
||
54 | * @throws TwitchSDKException |
||
55 | */ |
||
56 | public function blockTarget($user, $target, $queryString) |
||
60 | |||
61 | /** |
||
62 | * Removes $target from $user block list |
||
63 | * - requires scope 'user_blocks_edit' |
||
64 | * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#delete-usersuserblockstarget |
||
65 | * @param string $user |
||
66 | * @param string $target |
||
67 | * @param string $queryString |
||
68 | * @return \stdClass |
||
69 | * @throws TwitchSDKException |
||
70 | */ |
||
71 | public function removeTarget($user, $target, $queryString) |
||
75 | } |
||
76 |