| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 166 |
| Code Lines | 106 |
| 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 |
||
| 41 | public function output( $atts ) { |
||
| 42 | // @codingStandardsIgnoreLine |
||
| 43 | extract( shortcode_atts( array( |
||
| 44 | 'columns' => 3, |
||
| 45 | 'orderby' => 'name', |
||
| 46 | 'order' => 'ASC', |
||
| 47 | 'limit' => '-1', |
||
| 48 | 'include' => '', |
||
| 49 | 'display' => 'excerpt', |
||
| 50 | 'size' => 'lsx-thumbnail-single', |
||
| 51 | 'responsive' => 'true', |
||
| 52 | 'show_image' => 'true', |
||
| 53 | 'carousel' => 'true', |
||
| 54 | 'featured' => 'false', |
||
| 55 | ), $atts ) ); |
||
| 56 | |||
| 57 | $output = ''; |
||
| 58 | |||
| 59 | if ( 'true' === $responsive || true === $responsive ) { |
||
| 60 | $responsive = ' img-responsive'; |
||
| 61 | } else { |
||
| 62 | $responsive = ''; |
||
| 63 | } |
||
| 64 | |||
| 65 | $this->columns = $columns; |
||
| 66 | $this->responsive = $responsive; |
||
| 67 | |||
| 68 | if ( ! empty( $include ) ) { |
||
| 69 | $include = explode( ',', $include ); |
||
| 70 | |||
| 71 | $args = array( |
||
| 72 | 'post_type' => 'project', |
||
| 73 | 'posts_per_page' => $limit, |
||
| 74 | 'post__in' => $include, |
||
| 75 | 'orderby' => 'post__in', |
||
| 76 | 'order' => $order, |
||
| 77 | ); |
||
| 78 | } else { |
||
| 79 | $args = array( |
||
| 80 | 'post_type' => 'project', |
||
| 81 | 'posts_per_page' => $limit, |
||
| 82 | 'orderby' => $orderby, |
||
| 83 | 'order' => $order, |
||
| 84 | ); |
||
| 85 | |||
| 86 | if ( 'true' === $featured || true === $featured ) { |
||
| 87 | $args['meta_key'] = 'lsx_project_featured'; |
||
| 88 | $args['meta_value'] = 1; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | $projects = new \WP_Query( $args ); |
||
| 93 | |||
| 94 | if ( $projects->have_posts() ) { |
||
| 95 | global $post; |
||
| 96 | |||
| 97 | $count = 0; |
||
| 98 | $count_global = 0; |
||
| 99 | |||
| 100 | if ( 'true' === $carousel || true === $carousel ) { |
||
| 101 | $output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
||
| 102 | } else { |
||
| 103 | $output .= "<div class='lsx-projects-shortcode'><div class='row'>"; |
||
| 104 | } |
||
| 105 | |||
| 106 | while ( $projects->have_posts() ) { |
||
| 107 | $projects->the_post(); |
||
| 108 | |||
| 109 | // Count |
||
| 110 | $count++; |
||
| 111 | $count_global++; |
||
| 112 | |||
| 113 | // Content |
||
| 114 | if ( 'full' === $display ) { |
||
| 115 | $content = apply_filters( 'the_content', get_the_content() ); |
||
| 116 | $content = str_replace( ']]>', ']]>', $content ); |
||
| 117 | } elseif ( 'excerpt' === $display ) { |
||
| 118 | $content = apply_filters( 'the_excerpt', get_the_excerpt() ); |
||
| 119 | } |
||
| 120 | |||
| 121 | // Image |
||
| 122 | if ( 'true' === $show_image || true === $show_image ) { |
||
| 123 | if ( is_numeric( $size ) ) { |
||
| 124 | $thumb_size = array( $size, $size ); |
||
| 125 | } else { |
||
| 126 | $thumb_size = $size; |
||
| 127 | } |
||
| 128 | |||
| 129 | if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) { |
||
| 130 | $image = get_the_post_thumbnail( $post->ID, $thumb_size, array( |
||
| 131 | 'class' => $responsive, |
||
| 132 | ) ); |
||
| 133 | } else { |
||
| 134 | $image = ''; |
||
| 135 | } |
||
| 136 | |||
| 137 | if ( empty( $image ) ) { |
||
| 138 | if ( ! empty( $this->options['display']['projects_placeholder'] ) ) { |
||
| 139 | $image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />'; |
||
| 140 | } else { |
||
| 141 | $image = ''; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } else { |
||
| 145 | $image = ''; |
||
| 146 | } |
||
| 147 | |||
| 148 | // Project groups |
||
| 149 | $groups = ''; |
||
| 150 | $terms = get_the_terms( $post->ID, 'project-group' ); |
||
| 151 | |||
| 152 | if ( $terms && ! is_wp_error( $terms ) ) { |
||
| 153 | $groups = array(); |
||
| 154 | |||
| 155 | foreach ( $terms as $term ) { |
||
| 156 | $groups[] = $term->name; |
||
| 157 | } |
||
| 158 | |||
| 159 | $groups = join( ', ', $groups ); |
||
| 160 | } |
||
| 161 | |||
| 162 | $project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : ''; |
||
| 163 | |||
| 164 | if ( 'true' === $carousel || true === $carousel ) { |
||
| 165 | $output .= " |
||
| 166 | <div class='lsx-projects-slot'> |
||
| 167 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
||
| 168 | <h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
||
| 169 | $project_groups |
||
| 170 | <div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
||
| 171 | </div>'; |
||
| 172 | } elseif ( $columns >= 1 && $columns <= 4 ) { |
||
| 173 | $md_col_width = 12 / $columns; |
||
| 174 | |||
| 175 | $output .= " |
||
| 176 | <div class='col-xs-12 col-md-" . $md_col_width . "'> |
||
| 177 | <div class='lsx-projects-slot'> |
||
| 178 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
||
| 179 | <h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
||
| 180 | $project_groups |
||
| 181 | <div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
||
| 182 | </div> |
||
| 183 | </div>'; |
||
| 184 | |||
| 185 | if ( $count == $columns && $projects->post_count > $count_global ) { |
||
| 186 | $output .= '</div>'; |
||
| 187 | $output .= "<div class='row'>"; |
||
| 188 | $count = 0; |
||
| 189 | } |
||
| 190 | } else { |
||
| 191 | $output .= " |
||
| 192 | <p class='bg-warning' style='padding: 20px;'> |
||
| 193 | " . esc_html__( 'Invalid number of columns set. LSX Projects supports 1 to 4 columns.', 'lsx-projects' ) . ' |
||
| 194 | </p>'; |
||
| 195 | } |
||
| 196 | |||
| 197 | wp_reset_postdata(); |
||
| 198 | } |
||
| 199 | |||
| 200 | if ( 'true' !== $carousel && true !== $carousel ) { |
||
| 201 | $output .= '</div>'; |
||
| 202 | } |
||
| 203 | |||
| 204 | $output .= '</div>'; |
||
| 205 | |||
| 206 | return $output; |
||
| 207 | } |
||
| 214 |