| Conditions | 12 |
| Paths | 26 |
| Total Lines | 100 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 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 |
||
| 140 | public function install( $upgrading = false ) { |
||
| 141 | global $wp_filesystem; |
||
| 142 | |||
| 143 | $download_link = $this->get_download_link(); |
||
| 144 | $target_path = $this->get_directory(); |
||
| 145 | |||
| 146 | require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
||
| 147 | |||
| 148 | $upgrader = $this->get_upgrader(); |
||
| 149 | $upgrader->init(); |
||
| 150 | |||
| 151 | if ( ! $upgrading ) { |
||
| 152 | $upgrader->install_strings(); |
||
| 153 | } else { |
||
| 154 | $upgrader->upgrade_strings(); |
||
| 155 | } |
||
| 156 | |||
| 157 | $skin = $upgrader->skin; |
||
| 158 | |||
| 159 | $skin->header(); |
||
| 160 | |||
| 161 | // Connect to the Filesystem first. |
||
| 162 | $res = $upgrader->fs_connect( array( WP_CONTENT_DIR, $target_path ) ); |
||
| 163 | |||
| 164 | // Mainly for non-connected filesystem. |
||
| 165 | if ( ! $res ) { |
||
| 166 | $skin->footer(); |
||
| 167 | |||
| 168 | return false; |
||
| 169 | } |
||
| 170 | |||
| 171 | $skin->before(); |
||
| 172 | |||
| 173 | if ( is_wp_error( $res ) ) { |
||
| 174 | $this->cancel_installer( $skin, $res ); |
||
| 175 | |||
| 176 | return $res; |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Download the package (Note, This just returns the filename |
||
| 181 | * of the file if the package is a local file) |
||
| 182 | */ |
||
| 183 | $download = $upgrader->download_package( $download_link ); |
||
| 184 | if ( is_wp_error( $download ) ) { |
||
| 185 | $this->cancel_installer( $skin, $download ); |
||
| 186 | |||
| 187 | return $download; |
||
| 188 | } |
||
| 189 | |||
| 190 | // Unzips the file into a temporary directory. |
||
| 191 | $working_dir = $upgrader->unpack_package( $download, true ); |
||
| 192 | if ( is_wp_error( $working_dir ) ) { |
||
| 193 | $this->cancel_installer( $skin, $working_dir ); |
||
| 194 | |||
| 195 | return $working_dir; |
||
| 196 | } |
||
| 197 | |||
| 198 | $temporary_path = $target_path . '_upgrading'; |
||
| 199 | |||
| 200 | if ( $upgrading ) { |
||
| 201 | $upgrader->maintenance_mode( true ); |
||
| 202 | |||
| 203 | $skin->feedback( 'remove_old' ); |
||
| 204 | |||
| 205 | if ( is_dir( $temporary_path ) ) { |
||
| 206 | $wp_filesystem->delete( $temporary_path, true ); |
||
| 207 | } |
||
| 208 | |||
| 209 | // Move current install. |
||
| 210 | $wp_filesystem->move( $target_path, $temporary_path ); |
||
| 211 | } |
||
| 212 | |||
| 213 | $skin->feedback( 'installing_package' ); |
||
| 214 | |||
| 215 | $installed = $wp_filesystem->move( $working_dir . DIRECTORY_SEPARATOR . $this->get_slug() . '-master', $target_path ); |
||
| 216 | $wp_filesystem->delete( $working_dir, true ); |
||
| 217 | |||
| 218 | if ( $upgrading ) { |
||
| 219 | if ( false === $installed || is_wp_error( $installed ) ) { |
||
| 220 | // Restore old install. |
||
| 221 | $wp_filesystem->move( $temporary_path, $target_path ); |
||
| 222 | |||
| 223 | return false; |
||
| 224 | } else { |
||
| 225 | // Remove old install. |
||
| 226 | $wp_filesystem->delete( $temporary_path, true ); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | $upgrader->maintenance_mode( false ); |
||
| 231 | |||
| 232 | $skin->feedback( $installed ? 'process_success' : 'process_failed' ); |
||
| 233 | |||
| 234 | $skin->after(); |
||
| 235 | $skin->footer(); |
||
| 236 | |||
| 237 | // Done. |
||
| 238 | return true; |
||
| 239 | } |
||
| 240 | |||
| 263 |