| Conditions | 24 |
| Paths | 31 |
| Total Lines | 205 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 160 | private static function get_request_hierarchy_list($type) { |
||
| 161 | |||
| 162 | $views = array(); |
||
| 163 | |||
| 164 | // Home |
||
| 165 | |||
| 166 | if ( $type == 'home' ) : |
||
| 167 | |||
| 168 | $views[] = 'home'; |
||
| 169 | |||
| 170 | // Single |
||
| 171 | |||
| 172 | elseif ( $type == 'single' ) : |
||
| 173 | |||
| 174 | $post_type = get_post_type(); |
||
| 175 | |||
| 176 | $views[] = $post_type . '.single'; |
||
| 177 | |||
| 178 | $views[] = 'single'; |
||
| 179 | |||
| 180 | // Post type |
||
| 181 | |||
| 182 | elseif ( $type == 'post_type_archive' ) : |
||
| 183 | |||
| 184 | $post_type = get_post_type(); |
||
| 185 | |||
| 186 | $views[] = $post_type . '.archive'; |
||
| 187 | |||
| 188 | $views[] = 'archive'; |
||
| 189 | |||
| 190 | |||
| 191 | // Taxonomy |
||
| 192 | |||
| 193 | elseif ( $type == 'taxonomy' ): |
||
| 194 | |||
| 195 | $term = get_queried_object(); |
||
| 196 | |||
| 197 | if ( ! empty( $term->slug ) ) { |
||
| 198 | |||
| 199 | $taxonomy = $term->taxonomy; |
||
| 200 | |||
| 201 | $views[] = "taxonomy.$taxonomy-{$term->slug}"; |
||
| 202 | $views[] = "taxonomy.$taxonomy"; |
||
| 203 | |||
| 204 | } |
||
| 205 | |||
| 206 | $views[] = 'taxonomy.taxonomy'; |
||
| 207 | |||
| 208 | $views[] = 'taxonomy'; |
||
| 209 | |||
| 210 | // Category |
||
| 211 | |||
| 212 | elseif ( $type == 'category' ): |
||
| 213 | |||
| 214 | $category = get_queried_object(); |
||
| 215 | |||
| 216 | if ( ! empty( $category->slug ) ) { |
||
| 217 | $views[] = "category.{$category->slug}"; |
||
| 218 | $views[] = "category.{$category->term_id}"; |
||
| 219 | } |
||
| 220 | |||
| 221 | $views[] = 'category.category'; |
||
| 222 | |||
| 223 | $views[] = 'category'; |
||
| 224 | |||
| 225 | |||
| 226 | // Attachment |
||
| 227 | |||
| 228 | elseif ( $type == 'attachment' ): |
||
| 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 | |||
| 262 | // Tag |
||
| 263 | |||
| 264 | elseif ( $type == 'tag' ): |
||
| 265 | |||
| 266 | $tag = get_queried_object(); |
||
| 267 | |||
| 268 | if ( ! empty( $tag->slug ) ) { |
||
| 269 | $views[] = "post.tag.{$tag->slug}"; |
||
| 270 | $views[] = "post.tag.{$tag->term_id}"; |
||
| 271 | |||
| 272 | $views[] = "tag.{$tag->slug}"; |
||
| 273 | $views[] = "tag.{$tag->term_id}"; |
||
| 274 | } |
||
| 275 | $views[] = 'post.tag'; |
||
| 276 | |||
| 277 | $views[] = 'tag'; |
||
| 278 | |||
| 279 | |||
| 280 | // Author |
||
| 281 | |||
| 282 | elseif ( $type == 'author' ): |
||
| 283 | |||
| 284 | $author = get_queried_object(); |
||
| 285 | |||
| 286 | if ( $author instanceof WP_User ) { |
||
| 287 | $views[] = "post.author.{$author->user_nicename}"; |
||
| 288 | $views[] = "post.author.{$author->ID}"; |
||
| 289 | |||
| 290 | $views[] = "author.{$author->user_nicename}"; |
||
| 291 | $views[] = "author.{$author->ID}"; |
||
| 292 | } |
||
| 293 | |||
| 294 | $views[] = 'post.author'; |
||
| 295 | |||
| 296 | $views[] = 'author'; |
||
| 297 | |||
| 298 | |||
| 299 | // Front Page |
||
| 300 | |||
| 301 | elseif ( $type == 'front-page' ): |
||
| 302 | |||
| 303 | $views[] = 'front-page.front-page'; |
||
| 304 | $views[] = 'front-page'; |
||
| 305 | |||
| 306 | $views[] = 'home.home'; |
||
| 307 | $views[] = 'home'; |
||
| 308 | |||
| 309 | $views = array_merge($views, self::get_request_hierarchy_list('post_type_archive')); |
||
| 310 | |||
| 311 | // Page |
||
| 312 | |||
| 313 | elseif ( $type == 'classy-template' ): |
||
| 314 | |||
| 315 | $template = self::get_classy_template(); |
||
| 316 | |||
| 317 | $views[] = $template; |
||
| 318 | |||
| 319 | $views[] = 'page.' . $template; |
||
| 320 | |||
| 321 | $views[] = 'template.' . $template; |
||
| 322 | |||
| 323 | |||
| 324 | elseif ( $type == 'page' ): |
||
| 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 | |||
| 352 | // Default |
||
| 353 | |||
| 354 | else: |
||
| 355 | |||
| 356 | $views[] = $type; |
||
| 357 | |||
| 358 | endif; |
||
| 359 | |||
| 360 | $views[] = 'index'; |
||
| 361 | |||
| 362 | return $views; |
||
| 363 | |||
| 364 | } |
||
| 365 | |||
| 395 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.