Conditions | 12 |
Paths | 26 |
Total Lines | 100 |
Code Lines | 51 |
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 |
||
106 | public function install( $upgrading = false ) { |
||
107 | $download_link = $this->get_download_link(); |
||
108 | $target_path = $this->get_directory(); |
||
109 | |||
110 | require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
||
111 | |||
112 | $upgrader = $this->get_upgrader(); |
||
113 | $upgrader->init(); |
||
114 | |||
115 | if ( ! $upgrading ) { |
||
116 | $upgrader->install_strings(); |
||
117 | } else { |
||
118 | $upgrader->upgrade_strings(); |
||
119 | } |
||
120 | |||
121 | $skin = $upgrader->skin; |
||
122 | |||
123 | $skin->header(); |
||
124 | |||
125 | // Connect to the Filesystem first. |
||
126 | $res = $upgrader->fs_connect( array( WP_CONTENT_DIR, $target_path ) ); |
||
127 | |||
128 | // Mainly for non-connected filesystem. |
||
129 | if ( ! $res ) { |
||
130 | $skin->footer(); |
||
131 | |||
132 | return false; |
||
133 | } |
||
134 | |||
135 | $skin->before(); |
||
136 | |||
137 | if ( is_wp_error( $res ) ) { |
||
138 | $this->cancel_installer( $skin, $res ); |
||
139 | |||
140 | return $res; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Download the package (Note, This just returns the filename |
||
145 | * of the file if the package is a local file) |
||
146 | */ |
||
147 | $download = $upgrader->download_package( $download_link ); |
||
148 | if ( is_wp_error( $download ) ) { |
||
149 | $this->cancel_installer( $skin, $download ); |
||
150 | |||
151 | return $download; |
||
152 | } |
||
153 | |||
154 | // Unzips the file into a temporary directory. |
||
155 | $working_dir = $upgrader->unpack_package( $download, true ); |
||
156 | if ( is_wp_error( $working_dir ) ) { |
||
157 | $this->cancel_installer( $skin, $working_dir ); |
||
158 | |||
159 | return $working_dir; |
||
160 | } |
||
161 | |||
162 | $maintenance_mode = false; |
||
163 | $temporary_path = $target_path . '_upgrading'; |
||
164 | |||
165 | if ( $upgrading ) { |
||
166 | $maintenance_mode = $this->need_maintenance(); |
||
167 | $upgrader->maintenance_mode( $maintenance_mode ); |
||
168 | |||
169 | $skin->feedback( 'remove_old' ); |
||
170 | |||
171 | if ( is_dir( $temporary_path ) ) { |
||
172 | Stencil_File_System::remove( $temporary_path ); |
||
173 | } |
||
174 | |||
175 | // Move current install. |
||
176 | Stencil_File_System::move( $target_path, $temporary_path ); |
||
177 | |||
178 | $skin->feedback( 'installing_package' ); |
||
179 | |||
180 | } else { |
||
181 | $skin->feedback( 'installing_package' ); |
||
182 | } |
||
183 | |||
184 | $installed = Stencil_File_System::move( $working_dir . DIRECTORY_SEPARATOR . $this->get_slug() . '-master', $target_path ); |
||
185 | Stencil_File_System::remove( $working_dir ); |
||
186 | |||
187 | if ( $upgrading ) { |
||
188 | if ( false === $installed || is_wp_error( $installed ) ) { |
||
189 | // Restore old install. |
||
190 | Stencil_File_System::move( $temporary_path, $target_path ); |
||
191 | |||
192 | return false; |
||
193 | } else { |
||
194 | // Remove old install. |
||
195 | Stencil_File_System::remove( $temporary_path ); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | $upgrader->maintenance_mode( false ); |
||
200 | |||
201 | $skin->feedback( $installed ? 'process_success' : 'process_failed' ); |
||
202 | |||
203 | // Done. |
||
204 | return true; |
||
205 | } |
||
206 | |||
229 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.