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 |
||
56 | */ |
||
57 | const status_failed = 'MFL'; |
||
58 | |||
59 | |||
60 | /** |
||
61 | * indicates the message has been flagged for resending (at the time modified). |
||
62 | */ |
||
63 | const status_resend = 'MRS'; |
||
64 | |||
65 | |||
66 | /** |
||
67 | * indicates the message has been flagged for generation but has not been generated yet. Messages always start as this |
||
68 | * status when added to the queue. |
||
69 | */ |
||
70 | const status_incomplete = 'MIC'; |
||
71 | |||
72 | |||
73 | |||
74 | |||
75 | /** |
||
76 | * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
||
77 | * This status means that its possible to retry sending the message. |
||
78 | */ |
||
79 | const status_retry = 'MRT'; |
||
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | /** |
||
86 | * Private constructor to prevent direct creation. |
||
87 | * |
||
88 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
||
89 | * any incoming timezone data that gets saved). Note this just sends the timezone info to the |
||
90 | * date time model field objects. Default is null (and will be assumed using the set timezone |
||
91 | * in the 'timezone_string' wp option) |
||
92 | * |
||
93 | * @return EEM_Message |
||
|
|||
94 | */ |
||
95 | protected function __construct( $timezone = null ) { |
||
142 | |||
143 | |||
144 | |||
145 | /** |
||
146 | * @return \EE_Message |
||
147 | */ |
||
148 | public function create_default_object() { |
||
153 | |||
154 | |||
155 | |||
156 | /** |
||
157 | * @param mixed $cols_n_values |
||
158 | * @return \EE_Message |
||
159 | */ |
||
160 | public function instantiate_class_from_array_or_object( $cols_n_values ) { |
||
165 | |||
166 | |||
167 | |||
168 | /** |
||
169 | * Returns whether or not a message of that type was sent for a given attendee. |
||
170 | * @param EE_Attendee|int $attendee |
||
171 | * @param string $message_type the message type slug |
||
172 | * @return boolean |
||
173 | */ |
||
174 | View Code Duplication | public function message_sent_for_attendee( $attendee, $message_type ) { |
|
182 | |||
183 | |||
184 | |||
185 | |||
186 | /** |
||
187 | * Returns whether or not a message of that type was sent for a given registration |
||
188 | * @param EE_Registration|int $registration |
||
189 | * @param string $message_type the message type slug |
||
190 | * @return boolean |
||
191 | */ |
||
192 | View Code Duplication | public function message_sent_for_registration( $registration, $message_type ) { |
|
200 | |||
201 | |||
202 | |||
203 | |||
204 | /** |
||
205 | * This retrieves an EE_Message object from the db matching the given token string. |
||
206 | * @param string $token |
||
207 | * @return EE_Message | null |
||
208 | */ |
||
209 | public function get_one_by_token( $token ) { |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Returns stati that indicate the message HAS been sent |
||
218 | * @return array of strings for possible stati |
||
219 | */ |
||
220 | public function stati_indicating_sent(){ |
||
223 | |||
224 | |||
225 | |||
226 | |||
227 | /** |
||
228 | * Returns stati that indicate the message is waiting to be sent. |
||
229 | * @return array of strings for possible stati. |
||
230 | */ |
||
231 | public function stati_indicating_to_send() { |
||
234 | |||
235 | |||
236 | |||
237 | public function stati_indicating_failed_sending() { |
||
240 | |||
241 | |||
242 | |||
243 | |||
244 | /** |
||
245 | * Returns filterable array of all EEM_Message statuses. |
||
246 | * @return array |
||
247 | */ |
||
248 | public function all_statuses() { |
||
261 | |||
262 | /** |
||
263 | * Detects any specific query variables in the request and uses those to setup appropriate |
||
264 | * filter for any queries. |
||
265 | * @return array |
||
266 | */ |
||
267 | public function filter_by_query_params() { |
||
301 | |||
302 | |||
303 | } |
||
304 | // End of file EEM_Message.model.php |
||
306 |
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.