Conditions | 24 |
Paths | 31 |
Total Lines | 202 |
Code Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
162 | private static function get_request_hierarchy_list( $type ) { |
||
163 | |||
164 | $views = array(); |
||
165 | |||
166 | // Home |
||
167 | |||
168 | if ( 'home' === $type ) : |
||
169 | |||
170 | $views[] = 'home'; |
||
171 | |||
172 | // Single |
||
173 | |||
174 | elseif ( 'single' === $type ) : |
||
175 | |||
176 | $post_type = get_post_type(); |
||
177 | |||
178 | $views[] = $post_type . '.single'; |
||
179 | |||
180 | $views[] = 'single'; |
||
181 | |||
182 | // Post type |
||
183 | |||
184 | elseif ( 'post_type_archive' === $type ) : |
||
185 | |||
186 | $post_type = get_post_type(); |
||
187 | |||
188 | $views[] = $post_type . '.archive'; |
||
189 | |||
190 | $views[] = 'archive'; |
||
191 | |||
192 | // Taxonomy |
||
193 | |||
194 | elseif ( 'taxonomy' === $type ) : |
||
195 | |||
196 | $term = get_queried_object(); |
||
197 | |||
198 | if ( ! empty( $term->slug ) ) { |
||
199 | |||
200 | $taxonomy = $term->taxonomy; |
||
201 | |||
202 | $views[] = "taxonomy.$taxonomy-{$term->slug}"; |
||
203 | $views[] = "taxonomy.$taxonomy"; |
||
204 | |||
205 | } |
||
206 | |||
207 | $views[] = 'taxonomy.taxonomy'; |
||
208 | |||
209 | $views[] = 'taxonomy'; |
||
210 | |||
211 | // Category |
||
212 | |||
213 | elseif ( 'category' === $type ) : |
||
214 | |||
215 | $category = get_queried_object(); |
||
216 | |||
217 | if ( ! empty( $category->slug ) ) { |
||
218 | $views[] = "category.{$category->slug}"; |
||
219 | $views[] = "category.{$category->term_id}"; |
||
220 | } |
||
221 | |||
222 | $views[] = 'category.category'; |
||
223 | |||
224 | $views[] = 'category'; |
||
225 | |||
226 | // Attachment |
||
227 | |||
228 | elseif ( 'attachment' === $type ) : |
||
229 | |||
230 | $attachment = get_queried_object(); |
||
231 | |||
232 | if ( $attachment ) { |
||
233 | |||
234 | if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { |
||
235 | |||
236 | list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
||
237 | |||
238 | } else { |
||
239 | |||
240 | list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
||
241 | |||
242 | } |
||
243 | |||
244 | if ( ! empty( $subtype ) ) { |
||
245 | $views[] = "attachment.{$type}.{$subtype}"; |
||
246 | $views[] = "attachment.{$subtype}"; |
||
247 | |||
248 | $views[] = "{$type}.{$subtype}"; |
||
249 | $views[] = "{$subtype}"; |
||
250 | } |
||
251 | |||
252 | $views[] = "attachment.{$type}"; |
||
253 | $views[] = "{$type}"; |
||
254 | |||
255 | } |
||
256 | |||
257 | $views[] = 'attachment.attachment'; |
||
258 | |||
259 | $views[] = 'attachment'; |
||
260 | |||
261 | // Tag |
||
262 | |||
263 | elseif ( 'tag' === $type ) : |
||
264 | |||
265 | $tag = get_queried_object(); |
||
266 | |||
267 | if ( ! empty( $tag->slug ) ) { |
||
268 | $views[] = "post.tag.{$tag->slug}"; |
||
269 | $views[] = "post.tag.{$tag->term_id}"; |
||
270 | |||
271 | $views[] = "tag.{$tag->slug}"; |
||
272 | $views[] = "tag.{$tag->term_id}"; |
||
273 | } |
||
274 | $views[] = 'post.tag'; |
||
275 | |||
276 | $views[] = 'tag'; |
||
277 | |||
278 | // Author |
||
279 | |||
280 | elseif ( 'author' === $type ) : |
||
281 | |||
282 | $author = get_queried_object(); |
||
283 | |||
284 | if ( $author instanceof WP_User ) { |
||
285 | $views[] = "post.author.{$author->user_nicename}"; |
||
286 | $views[] = "post.author.{$author->ID}"; |
||
287 | |||
288 | $views[] = "author.{$author->user_nicename}"; |
||
289 | $views[] = "author.{$author->ID}"; |
||
290 | } |
||
291 | |||
292 | $views[] = 'post.author'; |
||
293 | |||
294 | $views[] = 'author'; |
||
295 | |||
296 | // Front Page |
||
297 | |||
298 | elseif ( 'front-page' === $type ) : |
||
299 | |||
300 | $views[] = 'front-page.front-page'; |
||
301 | $views[] = 'front-page'; |
||
302 | |||
303 | $views[] = 'home.home'; |
||
304 | $views[] = 'home'; |
||
305 | |||
306 | $views = array_merge( $views, self::get_request_hierarchy_list( 'post_type_archive' ) ); |
||
307 | |||
308 | // Page |
||
309 | |||
310 | elseif ( 'classy-template' === $type ) : |
||
311 | |||
312 | $template = self::get_classy_template(); |
||
313 | |||
314 | $views[] = $template; |
||
315 | |||
316 | $views[] = 'page.' . $template; |
||
317 | |||
318 | $views[] = 'template.' . $template; |
||
319 | |||
320 | $views[] = 'page.page'; |
||
321 | |||
322 | $views[] = 'page'; |
||
323 | |||
324 | elseif ( 'page' === $type ) : |
||
325 | |||
326 | $id = get_queried_object_id(); |
||
327 | |||
328 | $pagename = get_query_var( 'pagename' ); |
||
329 | |||
330 | if ( ! $pagename && $id ) { |
||
331 | // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
||
332 | $post = get_queried_object(); |
||
333 | |||
334 | if ( $post ) { |
||
335 | $pagename = $post->post_name; |
||
336 | } |
||
337 | } |
||
338 | |||
339 | if ( $pagename ) { |
||
340 | $views[] = 'page.' . $pagename; |
||
341 | } |
||
342 | |||
343 | if ( $id ) { |
||
344 | $views[] = 'page.' . $id; |
||
345 | } |
||
346 | |||
347 | $views[] = 'page.page'; |
||
348 | |||
349 | $views[] = 'page'; |
||
350 | |||
351 | // Default |
||
352 | |||
353 | else : |
||
354 | |||
355 | $views[] = $type; |
||
356 | |||
357 | endif; |
||
358 | |||
359 | $views[] = 'index'; |
||
360 | |||
361 | return $views; |
||
362 | |||
363 | } |
||
364 | |||
394 |