Conditions | 8 |
Paths | 5 |
Total Lines | 76 |
Code Lines | 58 |
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 |
||
37 | public static function widget() { |
||
38 | $number = self::get_count(); |
||
39 | $shares = ppp_get_shceduled_crons(); |
||
40 | |||
41 | if ( ! empty( $shares ) ) { |
||
42 | $limited_shares = array_slice( $shares, 0, $number, true ); |
||
43 | ?> |
||
44 | <div id="future-tweets" class="activity-block"> |
||
45 | <h4><?php _e( 'Post-Related shares', 'ppp-tweets' ); ?></h4> |
||
46 | <ul> |
||
47 | <?php |
||
48 | foreach ( $limited_shares as $key => $share ) { |
||
49 | $ppp_data = $share; |
||
50 | $timestamp = $ppp_data['timestamp']; |
||
51 | |||
52 | $name_parts = explode( '_', $ppp_data['args'][1] ); |
||
53 | $service = isset( $name_parts[3] ) ? $name_parts[3] : 'tw'; |
||
54 | $builder = 'ppp_' . $service . '_build_share_message'; |
||
55 | |||
56 | $post_id = $ppp_data['args'][0]; |
||
57 | $date = $timestamp + ( get_option( 'gmt_offset' ) * 3600 ); |
||
58 | $content = ''; |
||
59 | if ( function_exists( $builder ) ) { |
||
60 | $content = $builder( $ppp_data['args'][0], $ppp_data['args'][1], false ); |
||
61 | } |
||
62 | |||
63 | $regex = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@"; |
||
64 | $content = preg_replace( $regex, '', $content ); |
||
65 | ?> |
||
66 | <li> |
||
67 | <span class="meta"><i class="dashicons icon-ppp-<?php echo $service; ?>"></i> <?php echo date_i18n( 'M jS, ' . get_option( 'time_format' ), $date ); ?></span> |
||
68 | <a href="<?php echo admin_url( 'post.php?post=' . $post_id . '&action=edit' ); ?>"><?php echo $content; ?></a> |
||
69 | </li> |
||
70 | <?php } ?> |
||
71 | </ul> |
||
72 | <p> |
||
73 | <a class="button-primary" href="<?php echo admin_url( 'admin.php?page=ppp-schedule-info' ); ?>"><?php _e( 'View Full Schedule', 'ppp-txt' ); ?></a> |
||
74 | </p> |
||
75 | </div> |
||
76 | <?php |
||
77 | } else { |
||
78 | $args = array( |
||
79 | 'numberposts' => 1, |
||
80 | 'orderby' => 'post_date', |
||
81 | 'order' => 'DESC', |
||
82 | 'post_type' => ppp_allowed_post_types(), |
||
83 | 'post_status' => array( 'draft', 'publish', 'future' ), |
||
84 | ); |
||
85 | |||
86 | $recent_posts = wp_get_recent_posts( $args, ARRAY_A ); |
||
87 | $recent_post = $recent_posts[0]; |
||
88 | $post_type = get_post_type_object( $recent_post['post_type'] ); |
||
89 | $post_type_name = $post_type->labels->singular_name; |
||
90 | $edit_url = admin_url( 'post.php?post=' . $recent_post['ID'] . '&action=edit' ); |
||
91 | |||
92 | switch( $recent_post['post_status'] ) { |
||
93 | case 'draft': |
||
94 | $relative_time = __( '<a href="%s">Configure them</a> for your draft ' . $post_type_name, 'ppp-txt' ); |
||
95 | break; |
||
96 | case 'future': |
||
97 | $relative_time = __( '<a href="%s">Schedule one</a> for your upcoming ' . $post_type_name, 'ppp-txt' ); |
||
98 | break; |
||
99 | case 'publish': |
||
100 | default: |
||
101 | $relative_time = __( '<a href="%s">Schedule one</a> for your most recent ' . $post_type_name, 'ppp-txt' ); |
||
102 | break; |
||
103 | |||
104 | } |
||
105 | ?><span><em> |
||
106 | <?php _e( 'No scheduled shares at this time.', 'ppp-txt' ); ?> |
||
107 | <?php printf( $relative_time, $edit_url ); ?> |
||
108 | </em></span><?php |
||
109 | } |
||
110 | |||
111 | do_action( 'ppp_dashboard_shares' ); |
||
112 | } |
||
113 | |||
149 |