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 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
9 | class EEM_Message extends EEM_Base implements EEI_Query_Filter { |
||
10 | |||
11 | // private instance of the Message object |
||
12 | protected static $_instance = null; |
||
13 | |||
14 | |||
15 | /** |
||
16 | * This priority indicates a message should be generated and sent ASAP |
||
17 | * @type int |
||
18 | */ |
||
19 | const priority_high = 10; |
||
20 | |||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * This priority indicates a message should be generated ASAP and queued for sending. |
||
26 | * @type |
||
27 | */ |
||
28 | const priority_medium = 20; |
||
29 | |||
30 | |||
31 | |||
32 | |||
33 | /** |
||
34 | * This priority indicates a message should be queued for generating. |
||
35 | * @type int |
||
36 | */ |
||
37 | const priority_low = 30; |
||
38 | |||
39 | |||
40 | |||
41 | /** |
||
42 | * indicates this message was sent at the time modified |
||
43 | */ |
||
44 | const status_sent = 'MSN'; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * indicates this message is waiting to be sent |
||
49 | */ |
||
50 | const status_idle = 'MID'; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * indicates an attempt was a made to send this message |
||
55 | * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYs |
||
56 | * appear to the end user. |
||
57 | */ |
||
58 | const status_failed = 'MFL'; |
||
59 | |||
60 | |||
61 | /** |
||
62 | * indicates the message has been flagged for resending (at the time modified). |
||
63 | */ |
||
64 | const status_resend = 'MRS'; |
||
65 | |||
66 | |||
67 | /** |
||
68 | * indicates the message has been flagged for generation but has not been generated yet. Messages always start as this |
||
69 | * status when added to the queue. |
||
70 | */ |
||
71 | const status_incomplete = 'MIC'; |
||
72 | |||
73 | |||
74 | |||
75 | |||
76 | /** |
||
77 | * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
||
78 | * This status means that its possible to retry sending the message. |
||
79 | */ |
||
80 | const status_retry = 'MRT'; |
||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * This is for failed messages that are only displayed when `WP_DEBUG` is true. Usually this is used for more informational |
||
86 | * messages that may not indicate anything is broken. |
||
87 | */ |
||
88 | const status_debug_only = 'MDO'; |
||
89 | |||
90 | |||
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * Private constructor to prevent direct creation. |
||
96 | * |
||
97 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
||
98 | * any incoming timezone data that gets saved). Note this just sends the timezone info to the |
||
99 | * date time model field objects. Default is null (and will be assumed using the set timezone |
||
100 | * in the 'timezone_string' wp option) |
||
101 | * |
||
102 | * @return EEM_Message |
||
|
|||
103 | */ |
||
104 | protected function __construct( $timezone = null ) { |
||
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * @return \EE_Message |
||
156 | */ |
||
157 | public function create_default_object() { |
||
165 | |||
166 | |||
167 | |||
168 | /** |
||
169 | * @param mixed $cols_n_values |
||
170 | * @return \EE_Message |
||
171 | */ |
||
172 | public function instantiate_class_from_array_or_object( $cols_n_values ) { |
||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * Returns whether or not a message of that type was sent for a given attendee. |
||
185 | * @param EE_Attendee|int $attendee |
||
186 | * @param string $message_type the message type slug |
||
187 | * @return boolean |
||
188 | */ |
||
189 | View Code Duplication | public function message_sent_for_attendee( $attendee, $message_type ) { |
|
197 | |||
198 | |||
199 | |||
200 | |||
201 | /** |
||
202 | * Returns whether or not a message of that type was sent for a given registration |
||
203 | * @param EE_Registration|int $registration |
||
204 | * @param string $message_type the message type slug |
||
205 | * @return boolean |
||
206 | */ |
||
207 | View Code Duplication | public function message_sent_for_registration( $registration, $message_type ) { |
|
215 | |||
216 | |||
217 | |||
218 | |||
219 | /** |
||
220 | * This retrieves an EE_Message object from the db matching the given token string. |
||
221 | * @param string $token |
||
222 | * @return EE_Message |
||
223 | */ |
||
224 | public function get_one_by_token( $token ) { |
||
229 | |||
230 | |||
231 | /** |
||
232 | * Returns stati that indicate the message HAS been sent |
||
233 | * @return array of strings for possible stati |
||
234 | */ |
||
235 | public function stati_indicating_sent(){ |
||
238 | |||
239 | |||
240 | |||
241 | |||
242 | /** |
||
243 | * Returns stati that indicate the message is waiting to be sent. |
||
244 | * @return array of strings for possible stati. |
||
245 | */ |
||
246 | public function stati_indicating_to_send() { |
||
249 | |||
250 | |||
251 | |||
252 | public function stati_indicating_failed_sending() { |
||
255 | |||
256 | |||
257 | |||
258 | |||
259 | /** |
||
260 | * Returns filterable array of all EEM_Message statuses. |
||
261 | * @return array |
||
262 | */ |
||
263 | public function all_statuses() { |
||
277 | |||
278 | /** |
||
279 | * Detects any specific query variables in the request and uses those to setup appropriate |
||
280 | * filter for any queries. |
||
281 | * @return array |
||
282 | */ |
||
283 | public function filter_by_query_params() { |
||
311 | |||
312 | |||
313 | |||
314 | |||
315 | |||
316 | public function get_pretty_label_for_results() { |
||
380 | |||
381 | |||
382 | |||
383 | |||
384 | /** |
||
385 | * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
||
386 | * The array is in the format: |
||
387 | * |
||
388 | * array( |
||
389 | * {$field_name} => {$model_name} |
||
390 | * ); |
||
391 | * |
||
392 | * @since 4.9.0 |
||
393 | * @return array |
||
394 | */ |
||
395 | protected function _expected_vars_for_query_inject() { |
||
404 | |||
405 | |||
406 | } |
||
407 | // End of file EEM_Message.model.php |
||
409 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.