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 |
||
| 25 | class Give_Donor_Wall { |
||
|
|
|||
| 26 | /** |
||
| 27 | * Instance. |
||
| 28 | * |
||
| 29 | * @since 2.2.0 |
||
| 30 | * @access private |
||
| 31 | * @var Give_Donor_Wall |
||
| 32 | */ |
||
| 33 | static private $instance; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Singleton pattern. |
||
| 37 | * |
||
| 38 | * @since 2.2.0 |
||
| 39 | * @access private |
||
| 40 | */ |
||
| 41 | private function __construct() { |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * Get instance. |
||
| 47 | * |
||
| 48 | * @since 2.2.0 |
||
| 49 | * @access public |
||
| 50 | * @return Give_Donor_Wall |
||
| 51 | */ |
||
| 52 | View Code Duplication | public static function get_instance() { |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Setup the default hooks and actions |
||
| 64 | * |
||
| 65 | * @since 2.2.0 |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | */ |
||
| 69 | public function setup_actions() { |
||
| 77 | |||
| 78 | |||
| 79 | /** |
||
| 80 | * Displays donors in a grid layout. |
||
| 81 | * |
||
| 82 | * @since 2.2.0 |
||
| 83 | * |
||
| 84 | * @param array $atts { |
||
| 85 | * Optional. Attributes of the donor wall shortcode. |
||
| 86 | * |
||
| 87 | * @type int $donors_per_page Number of donors per page. Default '20'. |
||
| 88 | * @type int $form_id The donation form to filter donors by. Default is all forms (no filter). |
||
| 89 | * @type bool $paged Whether to paginate donors. Default 'true'. |
||
| 90 | * @type string $ids A comma-separated list of donor IDs to display. Default empty. |
||
| 91 | * @type string $columns Maximum columns to display. Default 'best-fit'. |
||
| 92 | * Accepts 'best-fit', '1', '2', '3', '4'. |
||
| 93 | * @type bool $show_avatar Whether to display the donor's gravatar image if available. Default 'true'. |
||
| 94 | * @type bool $show_name Whether to display the donor's full name, first and last. Default 'true'. |
||
| 95 | * @type bool $show_total Whether to display the donor's donation amount. Default 'true'. |
||
| 96 | * @type bool $show_time Whether to display date of the last donation. Default 'true'. |
||
| 97 | * @type bool $show_comments Whether to display the donor's comment if they left one. Default 'true'. |
||
| 98 | * @type int $comment_length The number of words to display for the comments before a "Read more" field |
||
| 99 | * displays. Default '20'. |
||
| 100 | * @type string $readmore_text Link label for modal in which donor can read full comment. |
||
| 101 | * @type string $loadmore_text Button label which will load more donor comments. |
||
| 102 | * @type int $avatar_size Avatar image size in pixels without the "px". Default "60" |
||
| 103 | * @type string $orderby The order in which you want the donors to appear. Accepts "donation_amount", "donation_count", |
||
| 104 | * if donor donated same value for orderby attribute then they will short by created date (fallback) |
||
| 105 | * @type string $order The order in which you want the donors to appear. Accepts "ASC". "DESC". |
||
| 106 | * |
||
| 107 | * } |
||
| 108 | * @return string|bool The markup of the form grid or false. |
||
| 109 | */ |
||
| 110 | public function render_shortcode( $atts ) { |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Parse shortcode attributes |
||
| 167 | * |
||
| 168 | * @since 2.2.0 |
||
| 169 | * @access public |
||
| 170 | * |
||
| 171 | * @param array $atts Shortcode attributes. |
||
| 172 | * |
||
| 173 | * @return array |
||
| 174 | */ |
||
| 175 | public function parse_atts( $atts ) { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Get donor query from shortcode attribiutes |
||
| 231 | * |
||
| 232 | * @since 2.2.0 |
||
| 233 | * @access public |
||
| 234 | * |
||
| 235 | * @param array $atts Shortcode attributes. |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | public function get_donor_query_atts( $atts ) { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get donors |
||
| 299 | * |
||
| 300 | * @since 2.2.0 |
||
| 301 | * @access public |
||
| 302 | * |
||
| 303 | * @param array $donor_query Dorno query. |
||
| 304 | * |
||
| 305 | * @return array |
||
| 306 | */ |
||
| 307 | public function get_donors( $donor_query ) { |
||
| 313 | |||
| 314 | |||
| 315 | /** |
||
| 316 | * Ajax handler |
||
| 317 | * |
||
| 318 | * @since 2.2.0 |
||
| 319 | * @access public |
||
| 320 | */ |
||
| 321 | public function ajax_handler() { |
||
| 347 | } |
||
| 348 | |||
| 351 |