| Conditions | 11 |
| Paths | 38 |
| Total Lines | 63 |
| Code Lines | 24 |
| 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 |
||
| 13 | protected function install() { |
||
| 14 | |||
| 15 | foreach ( $this->themes as $theme ) { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Filters whether to use an alternative process for installing a WordPress.com theme. |
||
| 19 | * The alternative process can be executed during the filter. |
||
| 20 | * |
||
| 21 | * The filter can also return an instance of WP_Error; in which case the endpoint response will |
||
| 22 | * contain this error. |
||
| 23 | * |
||
| 24 | * @module json-api |
||
| 25 | * |
||
| 26 | * @since 4.4.2 |
||
| 27 | * |
||
| 28 | * @param bool $use_alternative_install_method Whether to use the alternative method of installing |
||
| 29 | * a WPCom theme. |
||
| 30 | * @param string $theme_slug Theme name (slug). If it is a WPCom theme, |
||
| 31 | * it should be suffixed with `-wpcom`. |
||
| 32 | */ |
||
| 33 | $result = apply_filters( 'jetpack_wpcom_theme_install', false, $theme ); |
||
| 34 | |||
| 35 | $skin = null; |
||
|
|
|||
| 36 | $upgrader = null; |
||
| 37 | $link = null; |
||
| 38 | |||
| 39 | // If the alternative install method was not used, use the standard method. |
||
| 40 | if ( ! $result ) { |
||
| 41 | $skin = new Jetpack_Automatic_Install_Skin(); |
||
| 42 | $upgrader = new Theme_Upgrader( $skin ); |
||
| 43 | |||
| 44 | $link = $this->download_links[ $theme ]; |
||
| 45 | $result = $upgrader->install( $link ); |
||
| 46 | } |
||
| 47 | |||
| 48 | if ( file_exists( $link ) ) { |
||
| 49 | // Delete if link was tmp local file |
||
| 50 | unlink( $link ); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ( ! $this->bulk && is_wp_error( $result ) ) { |
||
| 54 | return $result; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ( ! $result ) { |
||
| 58 | $error = $this->log[ $theme ]['error'] = __( 'An unknown error occurred during installation', 'jetpack' ); |
||
| 59 | } |
||
| 60 | |||
| 61 | elseif ( ! self::is_installed_theme( $theme ) ) { |
||
| 62 | $error = $this->log[ $theme ]['error'] = __( 'There was an error installing your theme', 'jetpack' ); |
||
| 63 | } |
||
| 64 | |||
| 65 | elseif ( $upgrader ) { |
||
| 66 | $this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages(); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ( ! $this->bulk && isset( $error ) ) { |
||
| 71 | return new WP_Error( 'install_error', $error, 400 ); |
||
| 72 | } |
||
| 73 | |||
| 74 | return true; |
||
| 75 | } |
||
| 76 | |||
| 173 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.