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