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 |
||
| 22 | class Datetime extends Calculations_Base { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Calculates the total spaces available on the datetime, taking into account |
||
| 26 | * ticket limits too. |
||
| 27 | * |
||
| 28 | * @see EE_Datetime::spaces_remaining( true ) |
||
| 29 | * @param array $wpdb_row |
||
| 30 | * @param \WP_REST_Request $request |
||
| 31 | * @param Controller_Base $controller |
||
| 32 | * @return int |
||
| 33 | * @throws \EE_Error |
||
| 34 | */ |
||
| 35 | View Code Duplication | public static function spaces_remaining_considering_tickets( $wpdb_row, $request, $controller ){ |
|
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * Counts registrations who have checked into this datetime |
||
| 58 | * |
||
| 59 | * @param array $wpdb_row |
||
| 60 | * @param \WP_REST_Request $request |
||
| 61 | * @param Controller_Base $controller |
||
| 62 | * @return int |
||
| 63 | * @throws \EE_Error |
||
| 64 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
||
| 65 | */ |
||
| 66 | View Code Duplication | public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){ |
|
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | /** |
||
| 82 | * Counts registrations who have checked out of this datetime |
||
| 83 | * |
||
| 84 | * @param array $wpdb_row |
||
| 85 | * @param \WP_REST_Request $request |
||
| 86 | * @param Controller_Base $controller |
||
| 87 | * @return int |
||
| 88 | * @throws \EE_Error |
||
| 89 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
||
| 90 | */ |
||
| 91 | View Code Duplication | public static function registrations_checked_out_count( $wpdb_row, $request, $controller ){ |
|
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * Counts the number of pending-payment registrations for this event (regardless |
||
| 108 | * of how many datetimes each registrations' ticket purchase is for) |
||
| 109 | * |
||
| 110 | * @param array $wpdb_row |
||
| 111 | * @param \WP_REST_Request $request |
||
| 112 | * @param Controller_Base $controller |
||
| 113 | * @return int |
||
| 114 | * @throws \EE_Error |
||
| 115 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
||
| 116 | */ |
||
| 117 | View Code Duplication | public static function spots_taken_pending_payment( $wpdb_row, $request, $controller ){ |
|
| 138 | } |
||
| 139 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.