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 |
||
18 | class Datetime extends DatetimeCalculationBase |
||
19 | { |
||
20 | /** |
||
21 | * @var EEM_Datetime |
||
22 | */ |
||
23 | protected $datetime_model; |
||
24 | |||
25 | /** |
||
26 | * @var EEM_Registration |
||
27 | */ |
||
28 | protected $registration_model; |
||
29 | public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model) |
||
34 | |||
35 | /** |
||
36 | * Calculates the total spaces available on the datetime, taking into account |
||
37 | * ticket limits too. |
||
38 | * |
||
39 | * @see EE_Datetime::spaces_remaining( true ) |
||
40 | * @param array $wpdb_row |
||
41 | * @param WP_REST_Request $request |
||
42 | * @param DatetimeControllerBase $controller |
||
43 | * @return int |
||
44 | * @throws EE_Error |
||
45 | * @throws InvalidDataTypeException |
||
46 | * @throws InvalidInterfaceException |
||
47 | * @throws InvalidArgumentException |
||
48 | * @throws ReflectionException |
||
49 | */ |
||
50 | public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Counts registrations who have checked into this datetime |
||
77 | * |
||
78 | * @param array $wpdb_row |
||
79 | * @param WP_REST_Request $request |
||
80 | * @param DatetimeControllerBase $controller |
||
81 | * @return int |
||
82 | * @throws EE_Error |
||
83 | * @throws InvalidArgumentException |
||
84 | * @throws InvalidDataTypeException |
||
85 | * @throws InvalidInterfaceException |
||
86 | * @throws RestException |
||
87 | */ |
||
88 | View Code Duplication | public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
107 | |||
108 | |||
109 | /** |
||
110 | * Counts registrations who have checked out of this datetime |
||
111 | * |
||
112 | * @param array $wpdb_row |
||
113 | * @param WP_REST_Request $request |
||
114 | * @param DatetimeControllerBase $controller |
||
115 | * @return int |
||
116 | * @throws EE_Error |
||
117 | * @throws InvalidArgumentException |
||
118 | * @throws InvalidDataTypeException |
||
119 | * @throws InvalidInterfaceException |
||
120 | * @throws RestException |
||
121 | */ |
||
122 | View Code Duplication | public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
141 | |||
142 | |||
143 | /** |
||
144 | * Counts the number of pending-payment registrations for this event (regardless |
||
145 | * of how many datetimes each registrations' ticket purchase is for) |
||
146 | * |
||
147 | * @param array $wpdb_row |
||
148 | * @param WP_REST_Request $request |
||
149 | * @param DatetimeControllerBase $controller |
||
150 | * @return int |
||
151 | * @throws EE_Error |
||
152 | * @throws InvalidArgumentException |
||
153 | * @throws InvalidDataTypeException |
||
154 | * @throws InvalidInterfaceException |
||
155 | * @throws RestException |
||
156 | */ |
||
157 | View Code Duplication | public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
184 | |||
185 | |||
186 | /** |
||
187 | * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
||
188 | * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
||
189 | * |
||
190 | * @since $VID:$ |
||
191 | * @return array |
||
192 | */ |
||
193 | public function schemaForCalculations() |
||
226 | } |
||
227 |