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