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 |
||
12 | class EE_Messages_Scheduler extends EE_Base |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Number of seconds between batch sends/generates on the cron job. |
||
17 | * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
||
18 | * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
||
19 | * |
||
20 | * @type int |
||
21 | */ |
||
22 | const message_cron_schedule = 300; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | */ |
||
27 | public function __construct() |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Add custom schedules for wp_cron |
||
51 | * |
||
52 | * @param $schedules |
||
53 | */ |
||
54 | public function custom_schedules($schedules) |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
||
69 | * remove. |
||
70 | * |
||
71 | * @param array $tasks already existing scheduled tasks |
||
72 | * @return array |
||
73 | */ |
||
74 | public function register_scheduled_tasks($tasks) |
||
82 | |||
83 | |||
84 | /** |
||
85 | * This initiates a non-blocking separate request to execute on a scheduled task. |
||
86 | * Note: The EED_Messages module has the handlers for these requests. |
||
87 | * |
||
88 | * @param string $task The task the request is being generated for. |
||
89 | */ |
||
90 | public static function initiate_scheduled_non_blocking_request($task) |
||
117 | |||
118 | |||
119 | /** |
||
120 | * This returns |
||
121 | * the request params used for a scheduled message task request. |
||
122 | * |
||
123 | * @param string $task The task the request is for. |
||
124 | * @return array |
||
125 | */ |
||
126 | public static function get_request_params($task) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
||
140 | * |
||
141 | * @param string $task The task the request is being generated for. |
||
142 | */ |
||
143 | public static function initiate_immediate_request_on_cron($task) |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
||
156 | */ |
||
157 | View Code Duplication | public static function batch_generation() |
|
168 | |||
169 | |||
170 | /** |
||
171 | * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
||
172 | */ |
||
173 | View Code Duplication | public static function batch_sending() |
|
184 | |||
185 | |||
186 | /** |
||
187 | * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action. |
||
188 | * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete permanently |
||
189 | * from the database messages that have a MSG_modified date older than 30 days. |
||
190 | */ |
||
191 | public static function cleanup() |
||
209 | |||
210 | } //end EE_Messages_Scheduler |
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.