Conditions | 8 |
Paths | 16 |
Total Lines | 64 |
Code Lines | 31 |
Lines | 3 |
Ratio | 4.69 % |
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 |
||
127 | protected function update() { |
||
128 | |||
129 | wp_clean_plugins_cache(); |
||
130 | ob_start(); |
||
131 | wp_update_plugins(); // Check for Plugin updates |
||
132 | ob_end_clean(); |
||
133 | |||
134 | $update_plugins = get_site_transient( 'update_plugins' ); |
||
135 | |||
136 | if ( isset( $update_plugins->response ) ) { |
||
137 | $plugin_updates_needed = array_keys( $update_plugins->response ); |
||
138 | } else { |
||
139 | $plugin_updates_needed = array(); |
||
140 | } |
||
141 | |||
142 | $update_attempted = false; |
||
143 | |||
144 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
||
145 | |||
146 | // unhook this functions that output things before we send our response header. |
||
147 | remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); |
||
148 | remove_action( 'upgrader_process_complete', 'wp_version_check' ); |
||
149 | remove_action( 'upgrader_process_complete', 'wp_update_themes' ); |
||
150 | |||
151 | $result = false; |
||
152 | |||
153 | foreach ( $this->plugins as $plugin ) { |
||
154 | |||
155 | if ( ! in_array( $plugin, $plugin_updates_needed ) ) { |
||
156 | $this->log[ $plugin ][] = __( 'No update needed', 'jetpack' ); |
||
157 | continue; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Pre-upgrade action |
||
162 | * |
||
163 | * @since 3.9.3 |
||
164 | * |
||
165 | * @param array $plugin Plugin data |
||
166 | * @param array $plugin Array of plugin objects |
||
167 | * @param bool $updated_attempted false for the first update, true subsequently |
||
168 | */ |
||
169 | do_action('jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted); |
||
170 | |||
171 | $update_attempted = true; |
||
172 | |||
173 | // Object created inside the for loop to clean the messages for each plugin |
||
174 | $skin = new Automatic_Upgrader_Skin(); |
||
175 | // The Automatic_Upgrader_Skin skin shouldn't output anything. |
||
176 | $upgrader = new Plugin_Upgrader( $skin ); |
||
177 | $upgrader->init(); |
||
178 | // This avoids the plugin to be deactivated. |
||
179 | defined( 'DOING_CRON' ) or define( 'DOING_CRON', true ); |
||
180 | $result = $upgrader->upgrade( $plugin ); |
||
181 | |||
182 | $this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages(); |
||
183 | } |
||
184 | |||
185 | View Code Duplication | if ( ! $this->bulk && ! $result && $update_attempted ) { |
|
186 | return new WP_Error( 'update_fail', __( 'There was an error updating your plugin', 'jetpack' ), 400 ); |
||
187 | } |
||
188 | |||
189 | return $this->default_action(); |
||
190 | } |
||
191 | } |
||
192 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.