| Conditions | 10 |
| Paths | 50 |
| Total Lines | 60 |
| Code Lines | 34 |
| 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 |
||
| 21 | public static function get( $args = array() ) { |
||
| 22 | global $wp_query; |
||
| 23 | |||
| 24 | $defaults = array( |
||
| 25 | 'mid_size' => 2, |
||
| 26 | 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
||
| 27 | 'next_text' => '<i class="fas fa-chevron-right"></i>', |
||
| 28 | 'screen_reader_text' => __( 'Posts navigation' ), |
||
| 29 | 'before_page_number' => '', |
||
| 30 | 'after_page_number' => '', |
||
| 31 | 'type' => 'array', |
||
| 32 | 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1 |
||
| 33 | ); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Parse incoming $args into an array and merge it with $defaults |
||
| 37 | */ |
||
| 38 | $args = wp_parse_args( $args, $defaults ); |
||
| 39 | |||
| 40 | $output = ''; |
||
| 41 | |||
| 42 | // Don't print empty markup if there's only one page. |
||
| 43 | if ( $args['total'] > 1 ) { |
||
| 44 | |||
| 45 | // Set up paginated links. |
||
| 46 | $links = paginate_links( $args ); |
||
| 47 | |||
| 48 | // make the output bootstrap ready |
||
| 49 | $links_html = "<ul class='pagination m-0 p-0'>"; |
||
| 50 | if ( ! empty( $links ) ) { |
||
| 51 | foreach ( $links as $link ) { |
||
| 52 | $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
||
| 53 | $links_html .= "<li class='page-item $active'>"; |
||
| 54 | $links_html .= str_replace( "page-numbers", "page-link", $link ); |
||
| 55 | $links_html .= "</li>"; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | $links_html .= "</ul>"; |
||
| 59 | |||
| 60 | if ( $links ) { |
||
| 61 | $output .= '<section class="px-0 py-2 w-100">'; |
||
| 62 | $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
||
| 63 | $output .= '</section>'; |
||
| 64 | } |
||
| 65 | |||
| 66 | $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
||
| 67 | $output = str_replace( "nav-links", "aui-nav-links", $output ); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ( $output ) { |
||
| 71 | if ( ! empty( $args['before_paging'] ) ) { |
||
| 72 | $output = $args['before_paging'] . $output; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ( ! empty( $args['after_paging'] ) ) { |
||
| 76 | $output = $output . $args['after_paging']; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | return $output; |
||
| 81 | } |
||
| 83 | } |