| Conditions | 15 |
| Paths | 1153 |
| Total Lines | 77 |
| Code Lines | 40 |
| 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 |
||
| 131 | public function html( $args = array(), $output_image = true, $output_closing_tag = true ) { |
||
| 132 | if ( empty ( $this->url ) ) { |
||
| 133 | return ''; |
||
| 134 | } |
||
| 135 | |||
| 136 | $arg_defaults = array( |
||
| 137 | 'link' => 'image', |
||
| 138 | 'custom_link' => $this->custom_url |
||
| 139 | ); |
||
| 140 | |||
| 141 | $args = wp_parse_args( $args, $arg_defaults ); |
||
| 142 | |||
| 143 | $link = $args['link']; |
||
| 144 | |||
| 145 | $img = $this->html_img( $args ); |
||
| 146 | |||
| 147 | /* 12 Apr 2016 - PLEASE NOTE |
||
| 148 | We no longer just return the image html when "no link" option is chosen. |
||
| 149 | It was decided that it is better to return an anchor link with no href or target attributes. |
||
| 150 | This results in more standardized HTML output for better CSS and JS code |
||
| 151 | */ |
||
| 152 | |||
| 153 | if ( 'page' === $link ) { |
||
| 154 | //get the URL to the attachment page |
||
| 155 | $url = get_attachment_link( $this->ID ); |
||
| 156 | } else if ( 'custom' === $link ) { |
||
| 157 | $url = $args['custom_link']; |
||
| 158 | } else { |
||
| 159 | $url = $this->url; |
||
| 160 | } |
||
| 161 | |||
| 162 | //fallback for images that might not have a custom url |
||
| 163 | if ( empty( $url ) ) { |
||
| 164 | $url = $this->url; |
||
| 165 | } |
||
| 166 | |||
| 167 | $attr = array(); |
||
| 168 | |||
| 169 | //only add href and target attributes to the anchor if the link is NOT set to 'none' |
||
| 170 | if ( $link !== 'none' ){ |
||
| 171 | $attr['href'] = $url; |
||
| 172 | if ( ! empty( $this->custom_target ) && 'default' !== $this->custom_target ) { |
||
| 173 | $attr['target'] = $this->custom_target; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | if ( ! empty( $this->caption ) ) { |
||
| 178 | $attr['data-caption-title'] = $this->caption; |
||
| 179 | } |
||
| 180 | |||
| 181 | if ( !empty( $this->description ) ) { |
||
| 182 | $attr['data-caption-desc'] = $this->description; |
||
| 183 | } |
||
| 184 | |||
| 185 | $attr['data-attachment-id'] = $this->ID; |
||
| 186 | |||
| 187 | //pull any custom attributes out the args |
||
| 188 | if ( isset( $args['link_attributes'] ) && is_array( $args['link_attributes'] ) ) { |
||
| 189 | $attr = array_merge( $attr, $args['link_attributes'] ); |
||
| 190 | } |
||
| 191 | |||
| 192 | $attr = apply_filters( 'foogallery_attachment_html_link_attributes', $attr, $args, $this ); |
||
| 193 | $attr = array_map( 'esc_attr', $attr ); |
||
| 194 | $html = '<a '; |
||
| 195 | foreach ( $attr as $name => $value ) { |
||
| 196 | $html .= " $name=" . '"' . $value . '"'; |
||
| 197 | } |
||
| 198 | $html .= '>'; |
||
| 199 | if ( $output_image ) { |
||
| 200 | $html .= $img; |
||
| 201 | } |
||
| 202 | if ( $output_closing_tag ) { |
||
| 203 | $html .= '</a>'; |
||
| 204 | }; |
||
| 205 | |||
| 206 | return apply_filters( 'foogallery_attachment_html_link', $html, $args, $this ); |
||
| 207 | } |
||
| 208 | |||
| 247 |