| Conditions | 18 |
| Paths | 40 |
| Total Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 36 | function wpme_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
||
| 37 | global $wp_query; |
||
| 38 | |||
| 39 | $blog_id = Jetpack_Options::get_option( 'id' ); |
||
| 40 | |||
| 41 | if ( 'query' == $context ) { |
||
| 42 | if ( is_singular() ) { |
||
| 43 | $id = $wp_query->get_queried_object_id(); |
||
| 44 | $context = 'post'; |
||
| 45 | } elseif ( is_front_page() ) { |
||
| 46 | $context = 'blog'; |
||
| 47 | } else { |
||
| 48 | return ''; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | if ( 'blog' == $context ) { |
||
| 53 | if ( empty( $id ) ) |
||
| 54 | $id = $blog_id; |
||
| 55 | |||
| 56 | return 'https://wp.me/' . wpme_dec2sixtwo( $id ); |
||
| 57 | } |
||
| 58 | |||
| 59 | $post = get_post( $id ); |
||
| 60 | |||
| 61 | if ( empty( $post ) ) |
||
| 62 | return ''; |
||
| 63 | |||
| 64 | $post_id = $post->ID; |
||
| 65 | $type = ''; |
||
| 66 | |||
| 67 | if ( $allow_slugs && 'publish' == $post->post_status && 'post' == $post->post_type && strlen( $post->post_name ) <= 8 && false === strpos( $post->post_name, '%' ) |
||
| 68 | && false === strpos( $post->post_name, '-' ) ) { |
||
| 69 | $id = $post->post_name; |
||
| 70 | $type = 's'; |
||
| 71 | } else { |
||
| 72 | $id = wpme_dec2sixtwo( $post_id ); |
||
| 73 | if ( 'page' == $post->post_type ) |
||
| 74 | $type = 'P'; |
||
| 75 | elseif ( 'post' == $post->post_type || post_type_supports( $post->post_type, 'shortlinks' ) ) |
||
| 76 | $type= 'p'; |
||
| 77 | elseif ( 'attachment' == $post->post_type ) |
||
| 78 | $type = 'a'; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( empty( $type ) ) |
||
| 82 | return ''; |
||
| 83 | |||
| 84 | return 'https://wp.me/' . $type . wpme_dec2sixtwo( $blog_id ) . '-' . $id; |
||
| 85 | } |
||
| 86 | |||
| 133 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: