Complex classes like EE_System 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 EE_System, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class EE_System implements ActivatableInterface, ResettableInterface |
||
31 | { |
||
32 | |||
33 | |||
34 | /** |
||
35 | * @deprecated 4.9.40 |
||
36 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
37 | */ |
||
38 | const req_type_normal = 0; |
||
39 | |||
40 | /** |
||
41 | * @deprecated 4.9.40 |
||
42 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
43 | */ |
||
44 | const req_type_new_activation = 1; |
||
45 | |||
46 | /** |
||
47 | * @deprecated 4.9.40 |
||
48 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
49 | */ |
||
50 | const req_type_reactivation = 2; |
||
51 | |||
52 | /** |
||
53 | * @deprecated 4.9.40 |
||
54 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
55 | */ |
||
56 | const req_type_upgrade = 3; |
||
57 | |||
58 | /** |
||
59 | * @deprecated 4.9.40 |
||
60 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
61 | */ |
||
62 | const req_type_downgrade = 4; |
||
63 | |||
64 | /** |
||
65 | * @deprecated since version 4.6.0.dev.006 |
||
66 | * Now whenever a new_activation is detected the request type is still just |
||
67 | * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
||
68 | * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
||
69 | * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
||
70 | * (Specifically, when the migration manager indicates migrations are finished |
||
71 | * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
||
72 | */ |
||
73 | const req_type_activation_but_not_installed = 5; |
||
74 | |||
75 | /** |
||
76 | * @deprecated 4.9.40 |
||
77 | * @see \EventEspresso\core\services\activation\RequestTypeDetector |
||
78 | */ |
||
79 | const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
||
80 | |||
81 | |||
82 | /** |
||
83 | * @var EE_System $_instance |
||
84 | */ |
||
85 | private static $_instance; |
||
86 | |||
87 | /** |
||
88 | * @var EE_Registry $registry |
||
89 | */ |
||
90 | private $registry; |
||
91 | |||
92 | /** |
||
93 | * @var LoaderInterface $loader |
||
94 | */ |
||
95 | private $loader; |
||
96 | |||
97 | /** |
||
98 | * @var EE_Capabilities $capabilities |
||
99 | */ |
||
100 | private $capabilities; |
||
101 | |||
102 | /** |
||
103 | * @var EE_Maintenance_Mode $maintenance_mode |
||
104 | */ |
||
105 | private $maintenance_mode; |
||
106 | |||
107 | /** |
||
108 | * @var ActivationsAndUpgradesManager $activations_and_upgrades_manager |
||
109 | */ |
||
110 | private $activations_and_upgrades_manager; |
||
111 | |||
112 | /** |
||
113 | * @var ActivationHistory $activation_history |
||
114 | */ |
||
115 | private $activation_history; |
||
116 | |||
117 | /** |
||
118 | * @var \EventEspresso\core\services\activation\RequestType $request_type |
||
119 | */ |
||
120 | private $request_type; |
||
121 | |||
122 | /** |
||
123 | * @var bool $activation_detected |
||
124 | */ |
||
125 | private $activation_detected = false; |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * @singleton method used to instantiate class object |
||
131 | * @param EE_Registry|null $registry |
||
132 | * @param LoaderInterface|null $loader |
||
133 | * @param EE_Maintenance_Mode|null $maintenance_mode |
||
134 | * @return EE_System |
||
135 | */ |
||
136 | public static function instance( |
||
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * resets the instance and returns it |
||
156 | * |
||
157 | * @return EE_System |
||
158 | * @throws InvalidInterfaceException |
||
159 | * @throws InvalidDataTypeException |
||
160 | * @throws DomainException |
||
161 | * @throws InvalidArgumentException |
||
162 | * @throws InvalidEntityException |
||
163 | */ |
||
164 | public static function reset() |
||
174 | |||
175 | |||
176 | |||
177 | /** |
||
178 | * sets hooks for running rest of system |
||
179 | * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
||
180 | * starting EE Addons from any other point may lead to problems |
||
181 | * |
||
182 | * @param EE_Registry $registry |
||
183 | * @param LoaderInterface $loader |
||
184 | * @param EE_Maintenance_Mode $maintenance_mode |
||
185 | */ |
||
186 | private function __construct( |
||
253 | |||
254 | |||
255 | |||
256 | /** |
||
257 | * load and setup EE_Capabilities |
||
258 | * |
||
259 | * @return void |
||
260 | * @throws InvalidArgumentException |
||
261 | * @throws InvalidInterfaceException |
||
262 | * @throws InvalidDataTypeException |
||
263 | * @throws EE_Error |
||
264 | */ |
||
265 | public function loadCapabilities() |
||
275 | |||
276 | |||
277 | |||
278 | /** |
||
279 | * create and cache the CommandBus, and also add middleware |
||
280 | * The CapChecker middleware requires the use of EE_Capabilities |
||
281 | * which is why we need to load the CommandBus after Caps are set up |
||
282 | * |
||
283 | * @return void |
||
284 | * @throws EE_Error |
||
285 | */ |
||
286 | public function loadCommandBus() |
||
302 | |||
303 | |||
304 | |||
305 | /** |
||
306 | * @return void |
||
307 | * @throws EE_Error |
||
308 | */ |
||
309 | public function loadPluginApi() |
||
315 | |||
316 | |||
317 | |||
318 | /** |
||
319 | * Gets the ActivationHistory object for this addon |
||
320 | * |
||
321 | * @return ActivationHistory |
||
322 | */ |
||
323 | public function getActivationHistory() |
||
327 | |||
328 | |||
329 | |||
330 | /** |
||
331 | * @param ActivationHistory $activation_history |
||
332 | */ |
||
333 | public function setActivationHistory(ActivationHistory $activation_history) |
||
337 | |||
338 | |||
339 | |||
340 | /** |
||
341 | * @return RequestType |
||
342 | */ |
||
343 | public function getRequestType() |
||
347 | |||
348 | |||
349 | |||
350 | /** |
||
351 | * @param RequestType $request_type |
||
352 | */ |
||
353 | public function setRequestType(RequestType $request_type) |
||
357 | |||
358 | /** |
||
359 | * load_espresso_addons |
||
360 | * allow addons to load first so that they can set hooks for running DMS's, etc |
||
361 | * this is hooked into both: |
||
362 | * 'AHEE__EE_Bootstrap__load_core_configuration' |
||
363 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
364 | * and the WP 'activate_plugin' hook point |
||
365 | * |
||
366 | * @return void |
||
367 | * @throws EE_Error |
||
368 | */ |
||
369 | public function load_espresso_addons() |
||
393 | |||
394 | |||
395 | |||
396 | /** |
||
397 | * detect_activations_or_upgrades |
||
398 | * Checks for activation or upgrade of core first; |
||
399 | * then also checks if any registered addons have been activated or upgraded |
||
400 | * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
||
401 | * which runs during the WP 'plugins_loaded' action at priority 3 |
||
402 | * |
||
403 | * @return void |
||
404 | * @throws DomainException |
||
405 | * @throws InvalidArgumentException |
||
406 | * @throws InvalidEntityException |
||
407 | * @throws InvalidInterfaceException |
||
408 | * @throws InvalidDataTypeException |
||
409 | */ |
||
410 | public function detect_activations_or_upgrades() |
||
426 | |||
427 | |||
428 | |||
429 | /** |
||
430 | * load_core_configuration |
||
431 | * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
||
432 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
433 | * |
||
434 | * @return void |
||
435 | * @throws ReflectionException |
||
436 | */ |
||
437 | public function load_core_configuration() |
||
463 | |||
464 | |||
465 | |||
466 | /** |
||
467 | * cycles through all of the models/*.model.php files, and assembles an array of model names |
||
468 | * |
||
469 | * @return void |
||
470 | * @throws ReflectionException |
||
471 | */ |
||
472 | private function _parse_model_names() |
||
494 | |||
495 | |||
496 | |||
497 | /** |
||
498 | * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
||
499 | * that need to be setup before our EE_System launches. |
||
500 | * |
||
501 | * @return void |
||
502 | */ |
||
503 | private function _maybe_brew_regular() |
||
513 | |||
514 | |||
515 | |||
516 | /** |
||
517 | * register_shortcodes_modules_and_widgets |
||
518 | * generate lists of shortcodes and modules, then verify paths and classes |
||
519 | * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
||
520 | * which runs during the WP 'plugins_loaded' action at priority 7 |
||
521 | * |
||
522 | * @access public |
||
523 | * @return void |
||
524 | * @throws Exception |
||
525 | */ |
||
526 | public function register_shortcodes_modules_and_widgets() |
||
546 | |||
547 | |||
548 | |||
549 | /** |
||
550 | * _incompatible_addon_error |
||
551 | * |
||
552 | * @access public |
||
553 | * @return void |
||
554 | */ |
||
555 | private function _incompatible_addon_error() |
||
585 | |||
586 | |||
587 | |||
588 | /** |
||
589 | * brew_espresso |
||
590 | * begins the process of setting hooks for initializing EE in the correct order |
||
591 | * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
||
592 | * which runs during the WP 'plugins_loaded' action at priority 9 |
||
593 | * |
||
594 | * @return void |
||
595 | */ |
||
596 | public function brew_espresso() |
||
617 | |||
618 | |||
619 | |||
620 | /** |
||
621 | * set_hooks_for_core |
||
622 | * |
||
623 | * @access public |
||
624 | * @return void |
||
625 | * @throws EE_Error |
||
626 | */ |
||
627 | public function set_hooks_for_core() |
||
634 | |||
635 | |||
636 | |||
637 | /** |
||
638 | * perform_activations_upgrades_and_migrations |
||
639 | * |
||
640 | * @access public |
||
641 | * @return void |
||
642 | */ |
||
643 | public function perform_activations_upgrades_and_migrations() |
||
647 | |||
648 | |||
649 | |||
650 | /** |
||
651 | * load_CPTs_and_session |
||
652 | * |
||
653 | * @access public |
||
654 | * @return void |
||
655 | */ |
||
656 | public function load_CPTs_and_session() |
||
663 | |||
664 | |||
665 | |||
666 | /** |
||
667 | * load_controllers |
||
668 | * this is the best place to load any additional controllers that needs access to EE core. |
||
669 | * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
||
670 | * time |
||
671 | * |
||
672 | * @access public |
||
673 | * @return void |
||
674 | */ |
||
675 | public function load_controllers() |
||
688 | |||
689 | |||
690 | |||
691 | /** |
||
692 | * core_loaded_and_ready |
||
693 | * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
||
694 | * |
||
695 | * @access public |
||
696 | * @return void |
||
697 | */ |
||
698 | public function core_loaded_and_ready() |
||
709 | |||
710 | |||
711 | |||
712 | /** |
||
713 | * initialize |
||
714 | * this is the best place to begin initializing client code |
||
715 | * |
||
716 | * @access public |
||
717 | * @return void |
||
718 | */ |
||
719 | public function initialize() |
||
723 | |||
724 | |||
725 | |||
726 | /** |
||
727 | * initialize_last |
||
728 | * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
||
729 | * initialize has done so |
||
730 | * |
||
731 | * @access public |
||
732 | * @return void |
||
733 | */ |
||
734 | public function initialize_last() |
||
739 | |||
740 | |||
741 | |||
742 | /** |
||
743 | * @return void |
||
744 | * @throws EE_Error |
||
745 | */ |
||
746 | public function addEspressoToolbar() |
||
753 | |||
754 | |||
755 | |||
756 | /** |
||
757 | * do_not_cache |
||
758 | * sets no cache headers and defines no cache constants for WP plugins |
||
759 | * |
||
760 | * @access public |
||
761 | * @return void |
||
762 | */ |
||
763 | public static function do_not_cache() |
||
782 | |||
783 | |||
784 | |||
785 | /** |
||
786 | * extra_nocache_headers |
||
787 | * |
||
788 | * @access public |
||
789 | * @param $headers |
||
790 | * @return array |
||
791 | */ |
||
792 | public static function extra_nocache_headers($headers) |
||
800 | |||
801 | |||
802 | |||
803 | /** |
||
804 | * nocache_headers |
||
805 | * |
||
806 | * @access public |
||
807 | * @return void |
||
808 | */ |
||
809 | public static function nocache_headers() |
||
813 | |||
814 | |||
815 | |||
816 | |||
817 | /** |
||
818 | * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
||
819 | * never returned with the function. |
||
820 | * |
||
821 | * @param array $exclude_array any existing pages being excluded are in this array. |
||
822 | * @return array |
||
823 | */ |
||
824 | public function remove_pages_from_wp_list_pages($exclude_array) |
||
828 | |||
829 | |||
830 | |||
831 | /******************************** DEPRECATED ***************************************/ |
||
832 | |||
833 | |||
834 | |||
835 | /** |
||
836 | * @deprecated 4.9.40 |
||
837 | * @return void |
||
838 | */ |
||
839 | public function detect_if_activation_or_upgrade() |
||
842 | |||
843 | |||
844 | |||
845 | /** |
||
846 | * @deprecated 4.9.40 |
||
847 | * @param null $version_history |
||
848 | * @param null $current_version_to_add |
||
849 | * @return void |
||
850 | */ |
||
851 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
||
854 | |||
855 | |||
856 | |||
857 | /** |
||
858 | * @deprecated 4.9.40 |
||
859 | * @param null $espresso_db_update |
||
860 | * @return int one of the constants on EE_System::req_type_ |
||
861 | */ |
||
862 | public function detect_req_type($espresso_db_update = null) |
||
866 | |||
867 | |||
868 | |||
869 | /** |
||
870 | * @deprecated 4.9.40 |
||
871 | * @return bool |
||
872 | */ |
||
873 | public function is_major_version_change() |
||
877 | |||
878 | |||
879 | |||
880 | /** |
||
881 | * @deprecated 4.9.40 |
||
882 | * @param array $activation_history_for_addon |
||
883 | * @param string $activation_indicator_option_name |
||
884 | * @param string $version_to_upgrade_to |
||
885 | * @return int one of the constants on EE_System::req_type_* |
||
886 | */ |
||
887 | public static function detect_req_type_given_activation_history( |
||
894 | |||
895 | |||
896 | |||
897 | /** |
||
898 | * @deprecated 4.9.40 |
||
899 | * @param boolean $initialize_addons_too |
||
900 | * @param boolean $verify_schema |
||
901 | * @return void |
||
902 | * @throws EE_Error |
||
903 | */ |
||
904 | public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
||
907 | |||
908 | |||
909 | |||
910 | /** |
||
911 | * @deprecated 4.9.40 |
||
912 | * @throws EE_Error |
||
913 | */ |
||
914 | public function initialize_addons() |
||
917 | |||
918 | |||
919 | |||
920 | /** |
||
921 | * @deprecated 4.9.40 |
||
922 | * @return void |
||
923 | */ |
||
924 | public function redirect_to_about_ee() |
||
927 | |||
928 | |||
929 | } |
||
930 | // End of file EE_System.core.php |
||
932 |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):