Conditions | 21 |
Paths | 10370 |
Total Lines | 77 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
49 | public function get_rendered_html( $atts ) { |
||
50 | |||
51 | $theme = $this->theme; |
||
|
|||
52 | if ( ! empty( $atts['theme'] ) ) { |
||
53 | $theme = $atts['theme']; |
||
54 | } |
||
55 | |||
56 | $theme = $this->is_theme_available( $theme ); |
||
57 | |||
58 | $posts = $this->get_posts_to_display(); |
||
59 | |||
60 | if ( empty( $posts ) ) { |
||
61 | return ''; |
||
62 | } |
||
63 | |||
64 | if ( 'curated' === $this->sort && apply_filters( 'monsterinsights_popular_posts_inline_curated_shuffle', true ) ) { |
||
65 | // Randomize the order. |
||
66 | shuffle( $posts ); |
||
67 | } |
||
68 | |||
69 | $theme_styles = $this->get_theme_props( $theme )->get_theme(); |
||
70 | $limit = ! empty( $theme_styles['posts'] ) ? $theme_styles['posts'] : 1; |
||
71 | |||
72 | $label_text = ''; |
||
73 | if ( isset( $theme_styles['styles']['label'] ) ) { |
||
74 | $label_text = isset( $atts['labelText'] ) ? $atts['labelText'] : $theme_styles['styles']['label']['text']; |
||
75 | } |
||
76 | |||
77 | // Wrap in a P tag to keep the same spacing. |
||
78 | $html = '<div class="' . esc_attr($this->get_wrapper_class( $atts )) . '" '; |
||
79 | $html .= ! empty( $this->get_element_style( $theme, 'background', $atts ) ) ? 'style="' . esc_attr( $this->get_element_style( $theme, 'background', $atts ) ) . '"' : ''; |
||
80 | $html .= '>'; |
||
81 | |||
82 | if ( ! empty( $theme_styles['image'] ) && ! empty( $posts[0]['image'] ) ) { |
||
83 | $html .= '<div class="monsterinsights-inline-popular-posts-image">'; |
||
84 | $html .= '<img src="' . esc_url($posts[0]['image']) . '" srcset=" ' . esc_attr($posts[0]['srcset']) . ' " alt="' . esc_attr( $posts[0]['title'] ) . '" />'; |
||
85 | $html .= '</div>'; |
||
86 | } |
||
87 | $html .= '<div class="monsterinsights-inline-popular-posts-text">'; |
||
88 | if ( ! empty( $theme_styles['styles']['icon'] ) ) { |
||
89 | $html .= '<span class="monsterinsights-inline-popular-posts-icon" style=""><svg width="14" height="19" viewBox="0 0 14 19" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.875 0.899463C7.875 1.59183 8.0816 2.24711 8.49479 2.8653C8.93229 3.48349 9.44271 4.06458 10.026 4.60859C10.6337 5.15259 11.2292 5.73369 11.8125 6.35188C12.4201 6.97007 12.9306 7.76135 13.3438 8.72572C13.7812 9.66537 14 10.7163 14 11.8785C14 13.832 13.3073 15.5011 11.9219 16.8858C10.5608 18.2953 8.92014 19 7 19C5.07986 19 3.42708 18.2953 2.04167 16.8858C0.680556 15.5011 0 13.832 0 11.8785C0 9.94973 0.668403 8.28062 2.00521 6.87116C2.27257 6.57443 2.58854 6.50024 2.95312 6.64861C3.31771 6.79697 3.5 7.08134 3.5 7.50171V10.6545C3.5 11.3221 3.71875 11.8908 4.15625 12.3607C4.61806 12.8305 5.16493 13.0654 5.79688 13.0654C6.45312 13.0654 7.01215 12.8428 7.47396 12.3978C7.93576 11.9279 8.16667 11.3592 8.16667 10.6916C8.16667 10.2712 8.04514 9.86318 7.80208 9.46754C7.58333 9.0719 7.31597 8.71336 7 8.3919C6.68403 8.07044 6.34375 7.73662 5.97917 7.39043C5.63889 7.04425 5.34722 6.66097 5.10417 6.2406C4.88542 5.82024 4.73958 5.35041 4.66667 4.83114C4.59375 4.31186 4.67882 3.68131 4.92188 2.93948C5.18924 2.17293 5.63889 1.33219 6.27083 0.417277C6.51389 0.0463641 6.84201 -0.0772735 7.25521 0.0463641C7.6684 0.170002 7.875 0.454368 7.875 0.899463Z" fill="#EB5757"></path></svg></span>'; |
||
90 | } |
||
91 | if ( ! empty( $theme_styles['styles']['label'] ) ) { |
||
92 | $html .= '<span class="monsterinsights-inline-popular-posts-label" '; |
||
93 | $html .= ! empty( $this->get_element_style( $theme, 'label', $atts ) ) ? 'style="' . esc_attr( $this->get_element_style( $theme, 'label', $atts ) ) . '"' : ''; |
||
94 | $html .= '>' . esc_html( $label_text ) . '</span>'; |
||
95 | } |
||
96 | if ( ! empty( $theme_styles['styles']['border'] ) ) { |
||
97 | $html .= '<span class="monsterinsights-inline-popular-posts-border" '; |
||
98 | $html .= ! empty( $this->get_element_style( $theme, 'border', $atts, 'color' ) ) ? 'style="' . esc_attr( $this->get_element_style( $theme, 'border', $atts, 'color' ) ) . '"' : ''; |
||
99 | $html .= '></span>'; |
||
100 | } |
||
101 | if ( ! empty( $theme_styles['styles']['border']['color2'] ) ) { |
||
102 | $html .= '<span class="monsterinsights-inline-popular-posts-border-2" '; |
||
103 | $html .= ! empty( $this->get_element_style( $theme, 'border', $atts, 'color2' ) ) ? 'style="' . esc_attr( $this->get_element_style( $theme, 'border', $atts, 'color2' ) ) . '"' : ''; |
||
104 | $html .= '></span>'; |
||
105 | } |
||
106 | |||
107 | $display_count = 0; |
||
108 | foreach ( $posts as $post ) { |
||
109 | $display_count ++; |
||
110 | if ( $display_count > $limit ) { |
||
111 | break; |
||
112 | } |
||
113 | $this->set_post_shown( $post['id'] ); |
||
114 | $html .= '<div class="monsterinsights-inline-popular-posts-post">'; |
||
115 | $html .= '<a class="monsterinsights-inline-popular-posts-title" '; |
||
116 | $html .= ! empty( $this->get_element_style( $theme, 'title', $atts ) ) ? ' style="' . esc_attr( $this->get_element_style( $theme, 'title', $atts ) ) . '" ' : ''; |
||
117 | $html .= ' href="' . esc_url( $post['link'] ) . '">' . esc_html( $post['title'] ); |
||
118 | $html .= '</a>'; |
||
119 | $html .= '</div>'; |
||
120 | } |
||
121 | |||
122 | $html .= '</div>';// Text div. |
||
123 | $html .= '</div><p></p>';// Main div. |
||
124 | |||
125 | return $html; |
||
126 | |||
282 |