| Conditions | 8 | 
| Paths | 9 | 
| Total Lines | 51 | 
| Code Lines | 30 | 
| 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  | 
            ||
| 31 | 	function install() { | 
            ||
| 32 | $args = $this->input();  | 
            ||
| 33 | |||
| 34 | 		if ( isset( $args['zip'][0]['id'] ) ) { | 
            ||
| 35 | $attachment_id = $args['zip'][0]['id'];  | 
            ||
| 36 | $local_file = get_attached_file( $attachment_id );  | 
            ||
| 37 | 			if ( ! $local_file ) { | 
            ||
| 38 | return new WP_Error( 'local-file-does-not-exist' );  | 
            ||
| 39 | }  | 
            ||
| 40 | $skin = new Jetpack_Automatic_Install_Skin();  | 
            ||
| 41 | $upgrader = new Theme_Upgrader( $skin );  | 
            ||
| 42 | |||
| 43 | $pre_install_list = wp_get_themes();  | 
            ||
| 44 | $result = $upgrader->install( $local_file );  | 
            ||
| 45 | |||
| 46 | // clean up.  | 
            ||
| 47 | wp_delete_attachment( $attachment_id, true );  | 
            ||
| 48 | |||
| 49 | 			if ( is_wp_error( $result ) ) { | 
            ||
| 50 | return $result;  | 
            ||
| 51 | }  | 
            ||
| 52 | |||
| 53 | $after_install_list = wp_get_themes();  | 
            ||
| 54 | $plugin = array_values( array_diff( array_keys( $after_install_list ), array_keys( $pre_install_list ) ) );  | 
            ||
| 55 | |||
| 56 | 			if ( ! $result ) { | 
            ||
| 57 | $error_code = $upgrader->skin->get_main_error_code();  | 
            ||
| 58 | $message = $upgrader->skin->get_main_error_message();  | 
            ||
| 59 | 				if ( empty( $message ) ) { | 
            ||
| 60 | $message = __( 'An unknown error occurred during installation', 'jetpack' );  | 
            ||
| 61 | }  | 
            ||
| 62 | |||
| 63 | 				if ( 'download_failed' === $error_code ) { | 
            ||
| 64 | $error_code = 'no_package';  | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 | return new WP_Error( $error_code, $message, 400 );  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 70 | 			if ( empty( $plugin ) ) { | 
            ||
| 71 | return new WP_Error( 'theme_already_installed' );  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | $this->themes = $plugin;  | 
            ||
| 75 | $this->log[ $plugin[0] ] = $upgrader->skin->get_upgrade_messages();  | 
            ||
| 76 | |||
| 77 | return true;  | 
            ||
| 78 | }  | 
            ||
| 79 | |||
| 80 | return new WP_Error( 'no_theme_installed' );  | 
            ||
| 81 | }  | 
            ||
| 82 | }  | 
            ||
| 83 |