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 |
||
11 | class ParsePusher implements Pusher |
||
12 | { |
||
13 | /** |
||
14 | * Push message. |
||
15 | * |
||
16 | * @param WZRD\Contracts\Push\Notification $notification |
||
17 | * @param array $options |
||
18 | * |
||
19 | * Parse's specifics options : |
||
20 | * <code> |
||
21 | * $array = array( |
||
22 | * 'parse_query' => ParseInstallation::query(), |
||
23 | * 'parse_channels' => array('channel1', 'channel2'), |
||
24 | * 'parse_expiration_time' => new DateTime(), |
||
25 | * 'parse_push_time' => new DateTime() |
||
26 | * ); |
||
27 | * </code> |
||
28 | */ |
||
29 | public function push(NotificationContract $notification, array $options = []) |
||
63 | |||
64 | /** |
||
65 | * Create Parse query. |
||
66 | * |
||
67 | * @return Parse\ParseQuery |
||
68 | */ |
||
69 | protected function parseQuery() |
||
73 | |||
74 | /** |
||
75 | * Do Parse Push. |
||
76 | * |
||
77 | * @param array $data |
||
78 | */ |
||
79 | protected function parsePushSend($data) |
||
83 | |||
84 | /** |
||
85 | * Get supported platforms. |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | public function getSupportedPlatforms() |
||
93 | } |
||
94 |
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.