Complex classes like EED_Recaptcha often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EED_Recaptcha, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class EED_Recaptcha extends EED_Module |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var EE_Registration_Config $config |
||
27 | */ |
||
28 | private static $config; |
||
29 | |||
30 | /** |
||
31 | * @type bool $_not_a_robot |
||
32 | */ |
||
33 | private static $_not_a_robot; |
||
34 | |||
35 | /** |
||
36 | * @type string $_recaptcha_response |
||
37 | */ |
||
38 | private static $_recaptcha_response; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @return EED_Module|EED_Recaptcha |
||
43 | */ |
||
44 | public static function instance() |
||
48 | |||
49 | |||
50 | /** |
||
51 | * set_hooks - for hooking into EE Core, other modules, etc |
||
52 | * |
||
53 | * @return void |
||
54 | * @throws InvalidArgumentException |
||
55 | * @throws InvalidInterfaceException |
||
56 | * @throws InvalidDataTypeException |
||
57 | */ |
||
58 | public static function set_hooks() |
||
91 | |||
92 | |||
93 | /** |
||
94 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
||
95 | * |
||
96 | * @return void |
||
97 | * @throws InvalidArgumentException |
||
98 | * @throws InvalidInterfaceException |
||
99 | * @throws InvalidDataTypeException |
||
100 | */ |
||
101 | public static function set_hooks_admin() |
||
126 | |||
127 | |||
128 | /** |
||
129 | * @return void |
||
130 | */ |
||
131 | public static function set_definitions() |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @return void |
||
146 | */ |
||
147 | public static function set_late_hooks() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * @return boolean |
||
158 | */ |
||
159 | public static function useRecaptcha() |
||
164 | |||
165 | |||
166 | /** |
||
167 | * @return boolean |
||
168 | * @throws InvalidArgumentException |
||
169 | * @throws InvalidInterfaceException |
||
170 | * @throws InvalidDataTypeException |
||
171 | */ |
||
172 | public static function notPaymentOptionsRevisit() |
||
179 | |||
180 | |||
181 | /** |
||
182 | * @return void |
||
183 | * @throws InvalidArgumentException |
||
184 | * @throws InvalidInterfaceException |
||
185 | * @throws InvalidDataTypeException |
||
186 | */ |
||
187 | public static function enqueue_styles_and_scripts() |
||
216 | |||
217 | |||
218 | /** |
||
219 | * @param \WP $WP |
||
220 | */ |
||
221 | public function run($WP) |
||
224 | |||
225 | |||
226 | /** |
||
227 | * @return boolean |
||
228 | * @throws InvalidArgumentException |
||
229 | * @throws InvalidInterfaceException |
||
230 | * @throws InvalidDataTypeException |
||
231 | */ |
||
232 | public static function not_a_robot() |
||
239 | |||
240 | |||
241 | /** |
||
242 | * @return void |
||
243 | * @throws DomainException |
||
244 | * @throws InvalidArgumentException |
||
245 | * @throws InvalidInterfaceException |
||
246 | * @throws InvalidDataTypeException |
||
247 | */ |
||
248 | public static function display_recaptcha() |
||
268 | |||
269 | |||
270 | /** |
||
271 | * @return array |
||
272 | * @throws InvalidArgumentException |
||
273 | * @throws InvalidInterfaceException |
||
274 | * @throws InvalidDataTypeException |
||
275 | */ |
||
276 | public static function bypass_recaptcha_for_spco_load_payment_method() |
||
284 | |||
285 | |||
286 | /** |
||
287 | * @return boolean |
||
288 | * @throws InvalidArgumentException |
||
289 | * @throws InvalidInterfaceException |
||
290 | * @throws InvalidDataTypeException |
||
291 | */ |
||
292 | public static function recaptcha_passed() |
||
310 | |||
311 | |||
312 | /** |
||
313 | * @param array $recaptcha_response |
||
314 | * @return array |
||
315 | */ |
||
316 | public static function recaptcha_response($recaptcha_response = array()) |
||
326 | |||
327 | |||
328 | /** |
||
329 | * @return boolean |
||
330 | */ |
||
331 | private static function _bypass_recaptcha() |
||
354 | |||
355 | |||
356 | /** |
||
357 | * @return void |
||
358 | * @throws InvalidArgumentException |
||
359 | * @throws InvalidInterfaceException |
||
360 | * @throws InvalidDataTypeException |
||
361 | */ |
||
362 | private static function _get_recaptcha_response() |
||
369 | |||
370 | |||
371 | /** |
||
372 | * @return boolean |
||
373 | * @throws InvalidArgumentException |
||
374 | * @throws InvalidInterfaceException |
||
375 | * @throws InvalidDataTypeException |
||
376 | */ |
||
377 | private static function _process_recaptcha_response() |
||
401 | } |
||
402 | // End of file EED_Recaptcha.module.php |
||
404 |