Conditions | 9 |
Paths | 32 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
43 | public function get_active_plugins() { |
||
44 | global $jetpack_autoloader_activating_plugins_paths; |
||
45 | global $jetpack_autoloader_including_latest; |
||
46 | |||
47 | // We're going to build a unique list of plugins from a few different sources |
||
48 | // to find all of our "active" plugins. While we need to return an integer |
||
49 | // array, we're going to use an associative array internally to reduce |
||
50 | // the amount of time that we're going to spend checking uniqueness |
||
51 | // and merging different arrays together to form the output. |
||
52 | $active_plugins = array(); |
||
53 | |||
54 | // Make sure that plugins which have activated this request are considered as "active" even though |
||
55 | // they probably won't be present in any option. |
||
56 | if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
||
57 | foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
||
58 | $active_plugins[ $path ] = $path; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | // This option contains all of the plugins that have been activated. |
||
63 | $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
||
64 | foreach ( $plugins as $path ) { |
||
65 | $active_plugins[ $path ] = $path; |
||
66 | } |
||
67 | |||
68 | // This option contains all of the multisite plugins that have been activated. |
||
69 | if ( is_multisite() ) { |
||
70 | $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
||
71 | foreach ( $plugins as $path ) { |
||
72 | $active_plugins[ $path ] = $path; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $plugins = $this->plugin_locator->find_activating_this_request(); |
||
77 | foreach ( $plugins as $path ) { |
||
78 | $active_plugins[ $path ] = $path; |
||
79 | } |
||
80 | |||
81 | // When the current plugin isn't considered "active" there's a problem. |
||
82 | // Since we're here, the plugin is active and currently being loaded. |
||
83 | // We can support this case (mu-plugins and non-standard activation) |
||
84 | // by adding the current plugin to the active list and marking it |
||
85 | // as an unknown (activating) plugin. This also has the benefit |
||
86 | // of causing a reset because the active plugins list has |
||
87 | // been changed since it was saved in the global. |
||
88 | $current_plugin = $this->plugin_locator->find_current_plugin(); |
||
89 | if ( ! in_array( $current_plugin, $active_plugins, true ) && ! $jetpack_autoloader_including_latest ) { |
||
90 | $active_plugins[ $current_plugin ] = $current_plugin; |
||
91 | $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
||
92 | } |
||
93 | |||
94 | // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
||
95 | return array_values( $active_plugins ); |
||
96 | } |
||
97 | |||
151 |