Complex classes like Plugin 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 Plugin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | final class Plugin { |
||
18 | /** |
||
19 | * @var string The plugin version. |
||
20 | * |
||
21 | * @api |
||
22 | * @since 2.0 |
||
23 | */ |
||
24 | public static $version = GV_PLUGIN_VERSION; |
||
25 | |||
26 | /** |
||
27 | * @var string Minimum WordPress version. |
||
28 | * |
||
29 | * GravityView requires at least this version of WordPress to function properly. |
||
30 | */ |
||
31 | private static $min_wp_version = GV_MIN_WP_VERSION; |
||
32 | |||
33 | /** |
||
34 | * @var string Minimum Gravity Forms version. |
||
35 | * |
||
36 | * GravityView requires at least this version of Gravity Forms to function properly. |
||
37 | */ |
||
38 | public static $min_gf_version = GV_MIN_GF_VERSION; |
||
39 | |||
40 | /** |
||
41 | * @var string Minimum PHP version. |
||
42 | * |
||
43 | * GravityView requires at least this version of PHP to function properly. |
||
44 | */ |
||
45 | private static $min_php_version = GV_MIN_PHP_VERSION; |
||
46 | |||
47 | /** |
||
48 | * @var string|bool Minimum future PHP version. |
||
49 | * |
||
50 | * GravityView will require this version of PHP soon. False if no future PHP version changes are planned. |
||
51 | */ |
||
52 | private static $future_min_php_version = GV_FUTURE_MIN_PHP_VERSION; |
||
53 | |||
54 | /** |
||
55 | * @var string|bool Minimum future Gravity Forms version. |
||
56 | * |
||
57 | * GravityView will require this version of Gravity Forms soon. False if no future Gravity Forms version changes are planned. |
||
58 | */ |
||
59 | private static $future_min_gf_version = GV_FUTURE_MIN_GF_VERSION; |
||
60 | |||
61 | /** |
||
62 | * @var \GV\Plugin The \GV\Plugin static instance. |
||
63 | */ |
||
64 | private static $__instance = null; |
||
65 | |||
66 | /** |
||
67 | * @var \GV\Addon_Settings The plugin "addon" settings. |
||
68 | * |
||
69 | * @api |
||
70 | * @since 2.0 |
||
71 | */ |
||
72 | public $settings; |
||
73 | |||
74 | /** |
||
75 | * @var string The GFQuery functionality identifier. |
||
76 | */ |
||
77 | const FEATURE_GFQUERY = 'gfquery'; |
||
78 | |||
79 | /** |
||
80 | * @var string The joins functionality identifier. |
||
81 | */ |
||
82 | const FEATURE_JOINS = 'joins'; |
||
83 | |||
84 | /** |
||
85 | * @var string The unions functionality identifier. |
||
86 | */ |
||
87 | const FEATURE_UNIONS = 'unions'; |
||
88 | |||
89 | /** |
||
90 | * @var string The REST API functionality identifier. |
||
91 | */ |
||
92 | const FEATURE_REST = 'rest_api'; |
||
93 | |||
94 | /** |
||
95 | * Get the global instance of \GV\Plugin. |
||
96 | * |
||
97 | * @return \GV\Plugin The global instance of GravityView Plugin. |
||
98 | */ |
||
99 | public static function get() { |
||
105 | |||
106 | |||
107 | private function __construct() { |
||
123 | |||
124 | public function load_license_settings() { |
||
134 | |||
135 | /** |
||
136 | * Check whether GravityView is network activated. |
||
137 | * |
||
138 | * @return bool Whether it's network activated or not. |
||
139 | */ |
||
140 | 1 | public static function is_network_activated() { |
|
146 | |||
147 | /** |
||
148 | * Include more legacy stuff. |
||
149 | * |
||
150 | * @param boolean $force Whether to force the includes. |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | public function include_legacy_frontend( $force = false ) { |
||
175 | |||
176 | /** |
||
177 | * Load more legacy core files. |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | public function include_legacy_core() { |
||
239 | |||
240 | /** |
||
241 | * Load the translations. |
||
242 | * |
||
243 | * Order of look-ups: |
||
244 | * |
||
245 | * 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core) |
||
246 | * 2. /wp-content/mu-plugins/gravityview-{locale}.mo |
||
247 | * 3. /wp-content/mu-plugins/languages/gravityview-{locale}.mo |
||
248 | * 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo |
||
249 | * |
||
250 | * @return void |
||
251 | */ |
||
252 | public function load_textdomain() { |
||
288 | |||
289 | /** |
||
290 | * Register hooks that are fired when the plugin is activated and deactivated. |
||
291 | * |
||
292 | * @return void |
||
293 | */ |
||
294 | public function register_activation_hooks() { |
||
298 | |||
299 | /** |
||
300 | * Plugin activation function. |
||
301 | * |
||
302 | * @internal |
||
303 | * @return void |
||
304 | */ |
||
305 | 1 | public function activate() { |
|
333 | |||
334 | /** |
||
335 | * Plugin deactivation function. |
||
336 | * |
||
337 | * @internal |
||
338 | * @return void |
||
339 | */ |
||
340 | public function deactivate() { |
||
343 | |||
344 | /** |
||
345 | * Retrieve an absolute path within the GravityView plugin directory. |
||
346 | * |
||
347 | * @api |
||
348 | * @since 2.0 |
||
349 | * |
||
350 | * @param string $path Optional. Append this extra path component. |
||
351 | * @return string The absolute path to the plugin directory. |
||
352 | */ |
||
353 | 114 | public function dir( $path = '' ) { |
|
356 | |||
357 | /** |
||
358 | * Retrieve a relative path to the GravityView plugin directory from the WordPress plugin directory |
||
359 | * |
||
360 | * @api |
||
361 | * @since 2.2.3 |
||
362 | * |
||
363 | * @param string $path Optional. Append this extra path component. |
||
364 | * @return string The relative path to the plugin directory from the plugin directory. |
||
365 | */ |
||
366 | 1 | public function relpath( $path = '' ) { |
|
372 | |||
373 | /** |
||
374 | * Retrieve a URL within the GravityView plugin directory. |
||
375 | * |
||
376 | * @api |
||
377 | * @since 2.0 |
||
378 | * |
||
379 | * @param string $path Optional. Extra path appended to the URL. |
||
380 | * @return string The URL to this plugin, with trailing slash. |
||
381 | */ |
||
382 | 1 | public function url( $path = '/' ) { |
|
385 | |||
386 | /** |
||
387 | * Is everything compatible with this version of GravityView? |
||
388 | * |
||
389 | * @api |
||
390 | * @since 2.0 |
||
391 | * |
||
392 | * @return bool |
||
393 | */ |
||
394 | 5 | public function is_compatible() { |
|
400 | |||
401 | /** |
||
402 | * Is this version of GravityView compatible with the current version of PHP? |
||
403 | * |
||
404 | * @api |
||
405 | * @since 2.0 |
||
406 | * |
||
407 | * @return bool true if compatible, false otherwise. |
||
408 | */ |
||
409 | 5 | public function is_compatible_php() { |
|
412 | |||
413 | /** |
||
414 | * Is this version of GravityView compatible with the future required version of PHP? |
||
415 | * |
||
416 | * @api |
||
417 | * @since 2.0 |
||
418 | * |
||
419 | * @return bool true if compatible, false otherwise. |
||
420 | */ |
||
421 | public function is_compatible_future_php() { |
||
424 | |||
425 | /** |
||
426 | * Is this version of GravityView compatible with the current version of WordPress? |
||
427 | * |
||
428 | * @api |
||
429 | * @since 2.0 |
||
430 | * |
||
431 | * @param string $version Version to check against; otherwise uses GV_MIN_WP_VERSION |
||
432 | * |
||
433 | * @return bool true if compatible, false otherwise. |
||
434 | */ |
||
435 | 5 | public function is_compatible_wordpress( $version = null ) { |
|
443 | |||
444 | /** |
||
445 | * Is this version of GravityView compatible with the current version of Gravity Forms? |
||
446 | * |
||
447 | * @api |
||
448 | * @since 2.0 |
||
449 | * |
||
450 | * @return bool true if compatible, false otherwise (or not active/installed). |
||
451 | */ |
||
452 | 5 | public function is_compatible_gravityforms() { |
|
456 | |||
457 | /** |
||
458 | * Is this version of GravityView compatible with the future version of Gravity Forms? |
||
459 | * |
||
460 | * @api |
||
461 | * @since 2.0 |
||
462 | * |
||
463 | * @return bool true if compatible, false otherwise (or not active/installed). |
||
464 | */ |
||
465 | public function is_compatible_future_gravityforms() { |
||
469 | |||
470 | /** |
||
471 | * Retrieve the current PHP version. |
||
472 | * |
||
473 | * Overridable with GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE during testing. |
||
474 | * |
||
475 | * @return string The version of PHP. |
||
476 | */ |
||
477 | 4 | private function get_php_version() { |
|
481 | |||
482 | /** |
||
483 | * Retrieve the current WordPress version. |
||
484 | * |
||
485 | * Overridable with GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE during testing. |
||
486 | * |
||
487 | * @return string The version of WordPress. |
||
488 | */ |
||
489 | 4 | private function get_wordpress_version() { |
|
493 | |||
494 | /** |
||
495 | * Retrieve the current Gravity Forms version. |
||
496 | * |
||
497 | * Overridable with GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE during testing. |
||
498 | * |
||
499 | * @return string|null The version of Gravity Forms or null if inactive. |
||
500 | */ |
||
501 | 4 | private function get_gravityforms_version() { |
|
510 | |||
511 | /** |
||
512 | * Feature support detection. |
||
513 | * |
||
514 | * @param string $feature Feature name. Check FEATURE_* class constants. |
||
515 | * |
||
516 | * @return boolean |
||
517 | */ |
||
518 | 194 | public function supports( $feature ) { |
|
535 | |||
536 | /** |
||
537 | * Delete GravityView Views, settings, roles, caps, etc. |
||
538 | * |
||
539 | * @return void |
||
540 | */ |
||
541 | public function uninstall() { |
||
624 | |||
625 | private function __clone() { } |
||
626 | |||
627 | private function __wakeup() { } |
||
628 | } |
||
629 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: