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 ) { |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Check if admin preview email or not |
||
| 197 | * |
||
| 198 | * @since 2.0 |
||
| 199 | * @access public |
||
| 200 | * @return bool $is_preview |
||
| 201 | */ |
||
| 202 | View Code Duplication | public static function can_preview_email() { |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Check if admin preview email or not |
||
| 218 | * |
||
| 219 | * @since 2.0 |
||
| 220 | * @access public |
||
| 221 | * @return bool $is_preview |
||
| 222 | */ |
||
| 223 | View Code Duplication | public static function can_send_preview_email() { |
|
| 236 | |||
| 237 | |||
| 238 | /** |
||
| 239 | * Get formatted text for email content type. |
||
| 240 | * |
||
| 241 | * @since 2.0 |
||
| 242 | * @access public |
||
| 243 | * |
||
| 244 | * @param string $content_type |
||
| 245 | * |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public static function get_formatted_email_type( $content_type ) { |
||
| 256 | |||
| 257 | |||
| 258 | /** |
||
| 259 | * Get email notification option value. |
||
| 260 | * |
||
| 261 | * @since 2.0 |
||
| 262 | * @access public |
||
| 263 | * |
||
| 264 | * @param Give_Email_Notification $email |
||
| 265 | * @param string $option_name |
||
| 266 | * @param int $form_id |
||
| 267 | * @param mixed $default |
||
| 268 | * |
||
| 269 | * @return mixed |
||
| 270 | */ |
||
| 271 | public static function get_value( Give_Email_Notification $email, $option_name, $form_id = null, $default = false ) { |
||
| 307 | } |
||
| 308 |