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 |
||
14 | class MessagesAdmin extends CoreAdmin |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Context slug for the admin messages context. |
||
19 | * @var string |
||
20 | */ |
||
21 | const ADMIN_CONTEXT_SLUG = 'admin'; |
||
22 | |||
23 | /** |
||
24 | * Context slug for the primary attendee messages context |
||
25 | * @var string |
||
26 | */ |
||
27 | const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Status reference for the EEM_Message::status_sent status. |
||
32 | * @var string |
||
33 | */ |
||
34 | const MESSAGE_STATUS_SENT = 'MSN'; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Message type slug for the Payment Failed message type |
||
39 | */ |
||
40 | const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
||
41 | |||
42 | |||
43 | /** |
||
44 | * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
||
45 | * @var string |
||
46 | */ |
||
47 | const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
||
48 | '#global_messages_settings-do-messages-on-same-request'; |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
||
53 | * @var string |
||
54 | */ |
||
55 | const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * This is the container where active message types for a messenger are found/dragged to. |
||
60 | * @var string |
||
61 | */ |
||
62 | const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Locator for the context switcher selector on the Message Template Editor page. |
||
67 | * @var string |
||
68 | */ |
||
69 | const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Locator for the context switcher submit button in the Message Template Editor page. |
||
74 | * @var string |
||
75 | */ |
||
76 | const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Locator for the dialog container used for housing viewed messages in the message activity list table. |
||
81 | * @var string |
||
82 | */ |
||
83 | const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Returns the selector for the on/off toggle for context on the message template editor. |
||
88 | */ |
||
89 | const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE = |
||
90 | "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label"; |
||
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * @param string $additional_params Any additional request parameters for the generated url should be included as |
||
96 | * a string. |
||
97 | * @return string |
||
98 | */ |
||
99 | public static function messageActivityListTableUrl($additional_params = '') |
||
103 | |||
104 | |||
105 | /** |
||
106 | * @param string $additional_params Any additional request parameters for the generated url should be included as |
||
107 | * a string. |
||
108 | * @return string |
||
109 | */ |
||
110 | public static function defaultMessageTemplateListTableUrl($additional_params = '') |
||
114 | |||
115 | |||
116 | /** |
||
117 | * @param string $additional_params Any additional request parameters for the generated url should be included as |
||
118 | * a string. |
||
119 | * @return string |
||
120 | */ |
||
121 | public static function customMessageTemplateListTableUrl($additional_params = '') |
||
125 | |||
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | */ |
||
130 | public static function messageSettingsUrl() |
||
134 | |||
135 | |||
136 | |||
137 | public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
||
143 | |||
144 | |||
145 | /** |
||
146 | * @param string $message_type_slug |
||
147 | * @param string $context |
||
148 | * @return string |
||
149 | */ |
||
150 | public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
||
156 | |||
157 | |||
158 | /** |
||
159 | * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
||
160 | * |
||
161 | * @param $field |
||
162 | * @param $message_type_label |
||
163 | * @param string $message_status |
||
164 | * @param string $messenger |
||
165 | * @param string $context |
||
166 | * @param string $table_cell_content_for_field |
||
167 | * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
||
168 | * This allows you to indicate which item from the set to match. If this is set to 0 |
||
169 | * then all matches for the locator will be returned. |
||
170 | * @return string |
||
171 | * @throws \InvalidArgumentException |
||
172 | */ |
||
173 | public static function messagesActivityListTableCellSelectorFor( |
||
194 | |||
195 | |||
196 | /** |
||
197 | * Selector for the Create Custom button found in the message template list table. |
||
198 | * @param string $message_type_label |
||
199 | * @param string $messenger_label |
||
200 | * @return string |
||
201 | */ |
||
202 | public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
||
209 | |||
210 | |||
211 | /** |
||
212 | * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
||
213 | * the FIRST match (which will be the latest message sent if the table is default sorted). |
||
214 | * |
||
215 | * @param string $message_type_label The visible message type label for the row you want to match |
||
216 | * @param string $message_status The status of the message for the row you want to match. |
||
217 | * @param string $messenger The visible messenger label for the row you want to match. |
||
218 | * @param string $context The visible context label for the row you want to match. |
||
219 | * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
||
220 | * view. This allows you to indicate which item from the set to match. |
||
221 | * @return string |
||
222 | * @throws \InvalidArgumentException |
||
223 | */ |
||
224 | View Code Duplication | public static function messagesActivityListTableViewButtonSelectorFor( |
|
244 | |||
245 | |||
246 | /** |
||
247 | * Locator for the delete action link for a message item in the message activity list table. |
||
248 | * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
||
249 | * |
||
250 | * @param $message_type_label |
||
251 | * @param string $message_status |
||
252 | * @param string $messenger |
||
253 | * @param string $context |
||
254 | * @param int $number_in_set |
||
255 | * @return string |
||
256 | * @throws \InvalidArgumentException |
||
257 | */ |
||
258 | View Code Duplication | public static function messagesActivityListTableDeleteActionSelectorFor( |
|
277 | |||
278 | |||
279 | |||
280 | /** |
||
281 | * Returns the input selector for a given field in the message template editor. |
||
282 | * Assumes one is already viewing the Message Template Editor. |
||
283 | * @param string $field |
||
284 | * @return string |
||
285 | */ |
||
286 | public static function messageInputFieldSelectorFor($field) |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field. |
||
294 | */ |
||
295 | public static function messageTemplateToFieldSelector() |
||
299 | } |