| Conditions | 5 | 
| Paths | 9 | 
| Total Lines | 66 | 
| Code Lines | 30 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 5 | ||
| 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 | ||
| 59 | function strip_rss_dashboard_widget() { | ||
| 60 | // Get RSS Feed(s) | ||
| 61 | include_once(ABSPATH . WPINC . '/feed.php'); | ||
| 62 | |||
| 63 | // My feeds list (add your own RSS feeds urls) | ||
| 64 | $my_feeds = array( | ||
| 65 | 'https://silentcomics.com/feed.xml' | ||
| 66 | ); | ||
| 67 | |||
| 68 | // Loop through Feeds | ||
| 69 | foreach ( $my_feeds as $feed) : | ||
| 70 | |||
| 71 | // Get a SimplePie feed object from the specified feed source. | ||
| 72 | $rss = fetch_feed( $feed ); | ||
| 73 | if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly | ||
| 74 | // Figure out how many total items there are, and choose a limit | ||
| 75 | $maxitems = $rss->get_item_quantity( 3 ); | ||
| 76 | |||
| 77 | // Build an array of all the items, starting with element 0 (first element). | ||
| 78 | $rss_items = $rss->get_items( 0, $maxitems ); | ||
| 79 | |||
| 80 | // Get RSS title | ||
| 81 | $rss_title = '<a href="'.$rss->get_permalink().'" target="_blank">'.strtoupper( $rss->get_title() ).'</a>'; | ||
| 82 | endif; | ||
| 83 | |||
| 84 | // Display the container | ||
| 85 | echo '<div class="rss-widget">'; | ||
| 86 | echo '<strong>'.$rss_title.'</strong>'; | ||
| 87 | echo '<hr style="border: 0; background-color: #DFDFDF; height: 1px;">'; | ||
| 88 | |||
| 89 | // Starts items listing within <ul> tag | ||
| 90 | echo '<ul>'; | ||
| 91 | |||
| 92 | // Check items | ||
| 93 | 		if ( $maxitems == 0 ) { | ||
| 94 | echo '<li>'.__( 'No item', 'strip').'.</li>'; | ||
| 95 | 		} { | ||
| 96 | // Loop through each feed item and display each item as a hyperlink. | ||
| 97 | foreach ( $rss_items as $item ) : | ||
| 98 | // Uncomment line below to display non human date | ||
| 99 | 				//$item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); | ||
| 100 | |||
| 101 | // Get human date (comment if you want to use non human date) | ||
| 102 | 				$item_date = human_time_diff( $item->get_date('U'), current_time('timestamp')).' '.__( 'ago', 'strip' ); | ||
| 103 | |||
| 104 | // Start displaying item content within a <li> tag | ||
| 105 | echo '<li>'; | ||
| 106 | // create item link | ||
| 107 | echo '<a href="'.esc_url( $item->get_permalink() ).'" title="'.$item_date.'">'; | ||
| 108 | // Get item title | ||
| 109 | echo esc_html( $item->get_title() ); | ||
| 110 | echo '</a>'; | ||
| 111 | // Display date | ||
| 112 | echo ' <span class="rss-date">'.$item_date.'</span><br />'; | ||
| 113 | // Get item content | ||
| 114 | $content = $item->get_content(); | ||
| 115 | // Shorten content | ||
| 116 | $content = wp_html_excerpt($content, 120) . ' [...]'; | ||
| 117 | // Display content | ||
| 118 | echo $content; | ||
| 119 | // End <li> tag | ||
| 120 | echo '</li>'; | ||
| 121 | endforeach; | ||
| 122 | } | ||
| 123 | // End <ul> tag | ||
| 124 | echo '</ul></div>'; | ||
| 125 | |||
| 201 |