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 |
||
20 | class Give_Email_Notification_Util { |
||
|
|||
21 | /** |
||
22 | * Instance. |
||
23 | * |
||
24 | * @since 2.0 |
||
25 | * @access static |
||
26 | * @var |
||
27 | */ |
||
28 | static private $instance; |
||
29 | |||
30 | /** |
||
31 | * Singleton pattern. |
||
32 | * |
||
33 | * @since 2.0 |
||
34 | * @access private |
||
35 | * Give_Email_Notification_Util constructor. |
||
36 | */ |
||
37 | private function __construct() { |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Get instance. |
||
43 | * |
||
44 | * @since 2.0 |
||
45 | * @access static |
||
46 | * @return static |
||
47 | */ |
||
48 | static function get_instance() { |
||
55 | |||
56 | |||
57 | /** |
||
58 | * Check if notification has preview field or not. |
||
59 | * |
||
60 | * @since 2.0 |
||
61 | * @access public |
||
62 | * |
||
63 | * @param Give_Email_Notification $email |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public static function has_preview( Give_Email_Notification $email ) { |
||
70 | |||
71 | /** |
||
72 | * Check if notification has recipient field or not. |
||
73 | * |
||
74 | * @since 2.0 |
||
75 | * @access public |
||
76 | * |
||
77 | * @param Give_Email_Notification $email |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public static function has_recipient_field( Give_Email_Notification $email ) { |
||
84 | |||
85 | /** |
||
86 | * Check if admin can edit notification status or not. |
||
87 | * |
||
88 | * @since 2.0 |
||
89 | * @access public |
||
90 | * |
||
91 | * @param Give_Email_Notification $email |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public static function is_notification_status_editable( Give_Email_Notification $email ) { |
||
100 | |||
101 | /** |
||
102 | * Check if admin can edit notification status or not. |
||
103 | * |
||
104 | * @since 2.0 |
||
105 | * @access public |
||
106 | * |
||
107 | * @param Give_Email_Notification $email |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public static function is_content_type_editable( Give_Email_Notification $email ) { |
||
114 | |||
115 | /** |
||
116 | * Check email preview header active or not. |
||
117 | * |
||
118 | * @since 2.0 |
||
119 | * @access public |
||
120 | * |
||
121 | * @param Give_Email_Notification $email |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public static function is_email_preview_has_header( Give_Email_Notification $email ) { |
||
128 | |||
129 | /** |
||
130 | * Check email preview header active or not. |
||
131 | * |
||
132 | * @since 2.0 |
||
133 | * @access public |
||
134 | * |
||
135 | * @param Give_Email_Notification $email |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | public static function is_email_preview( Give_Email_Notification $email ) { |
||
142 | |||
143 | /** |
||
144 | * Check if email notification setting appear on emails setting page or not. |
||
145 | * |
||
146 | * @since 2.0 |
||
147 | * @access public |
||
148 | * |
||
149 | * @param Give_Email_Notification $email |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public static function is_show_on_emails_setting_page( Give_Email_Notification $email ){ |
||
156 | |||
157 | /** |
||
158 | * Check if we can use form email options. |
||
159 | * |
||
160 | * @since 2.0 |
||
161 | * @access public |
||
162 | * |
||
163 | * @param Give_Email_Notification $email |
||
164 | * @param int $form_id |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public static function can_use_form_email_options( Give_Email_Notification $email, $form_id = null ){ |
||
171 | |||
172 | /** |
||
173 | * Check email active or not. |
||
174 | * |
||
175 | * @since 2.0 |
||
176 | * @access public |
||
177 | * |
||
178 | * @param Give_Email_Notification $email |
||
179 | * @param int $form_id |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public static function is_email_notification_active( Give_Email_Notification $email, $form_id = null ) { |
||
205 | |||
206 | /** |
||
207 | * Check if admin preview email or not |
||
208 | * |
||
209 | * @since 2.0 |
||
210 | * @access public |
||
211 | * @return bool $is_preview |
||
212 | */ |
||
213 | View Code Duplication | public static function can_preview_email() { |
|
226 | |||
227 | /** |
||
228 | * Check if admin preview email or not |
||
229 | * |
||
230 | * @since 2.0 |
||
231 | * @access public |
||
232 | * @return bool $is_preview |
||
233 | */ |
||
234 | View Code Duplication | public static function can_send_preview_email() { |
|
247 | |||
248 | |||
249 | /** |
||
250 | * Get formatted text for email content type. |
||
251 | * |
||
252 | * @since 2.0 |
||
253 | * @access public |
||
254 | * |
||
255 | * @param string $content_type |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | public static function get_formatted_email_type( $content_type ) { |
||
267 | |||
268 | |||
269 | /** |
||
270 | * Get email notification option value. |
||
271 | * |
||
272 | * @since 2.0 |
||
273 | * @access public |
||
274 | * |
||
275 | * @param Give_Email_Notification $email |
||
276 | * @param string $option_name |
||
277 | * @param int $form_id |
||
278 | * @param mixed $default |
||
279 | * |
||
280 | * @return mixed |
||
281 | */ |
||
282 | public static function get_value( Give_Email_Notification $email, $option_name, $form_id = null, $default = false ) { |
||
318 | |||
319 | |||
320 | /** |
||
321 | * Get email logo. |
||
322 | * |
||
323 | * @since 2.1.5 |
||
324 | * |
||
325 | * @access public |
||
326 | * |
||
327 | * @param integer $form_id FOrm ID. |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | public static function get_email_logo( $form_id ) { |
||
340 | } |
||
341 |