| Conditions | 14 |
| Paths | 770 |
| Total Lines | 74 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 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 | //if there is no link, then just return the image tag |
||
| 148 | if ( 'none' === $link ) { |
||
| 149 | return $img; |
||
| 150 | } |
||
| 151 | |||
| 152 | if ( 'page' === $link ) { |
||
| 153 | //get the URL to the attachment page |
||
| 154 | $url = get_attachment_link( $this->ID ); |
||
| 155 | } else if ( 'custom' === $link ) { |
||
| 156 | $url = $args['custom_link']; |
||
| 157 | } else { |
||
| 158 | $url = $this->url; |
||
| 159 | } |
||
| 160 | |||
| 161 | //fallback for images that might not have a custom url |
||
| 162 | if ( empty( $url ) ) { |
||
| 163 | $url = $this->url; |
||
| 164 | } |
||
| 165 | |||
| 166 | $attr = array(); |
||
| 167 | |||
| 168 | $attr['href'] = $url; |
||
| 169 | |||
| 170 | if ( ! empty( $this->custom_target ) ) { |
||
| 171 | $attr['target'] = $this->custom_target; |
||
| 172 | } |
||
| 173 | |||
| 174 | if ( ! empty( $this->caption ) ) { |
||
| 175 | $attr['data-caption-title'] = $this->caption; |
||
| 176 | } |
||
| 177 | |||
| 178 | if ( !empty( $this->description ) ) { |
||
| 179 | $attr['data-caption-desc'] = $this->description; |
||
| 180 | } |
||
| 181 | |||
| 182 | $attr['data-attachment-id'] = $this->ID; |
||
| 183 | |||
| 184 | //pull any custom attributes out the args |
||
| 185 | if ( isset( $args['link_attributes'] ) && is_array( $args['link_attributes'] ) ) { |
||
| 186 | $attr = array_merge( $attr, $args['link_attributes'] ); |
||
| 187 | } |
||
| 188 | |||
| 189 | $attr = apply_filters( 'foogallery_attachment_html_link_attributes', $attr, $args, $this ); |
||
| 190 | $attr = array_map( 'esc_attr', $attr ); |
||
| 191 | $html = '<a '; |
||
| 192 | foreach ( $attr as $name => $value ) { |
||
| 193 | $html .= " $name=" . '"' . $value . '"'; |
||
| 194 | } |
||
| 195 | $html .= '>'; |
||
| 196 | if ( $output_image ) { |
||
| 197 | $html .= $img; |
||
| 198 | } |
||
| 199 | if ( $output_closing_tag ) { |
||
| 200 | $html .= '</a>'; |
||
| 201 | }; |
||
| 202 | |||
| 203 | return apply_filters( 'foogallery_attachment_html_link', $html, $args, $this ); |
||
| 204 | } |
||
| 205 | |||
| 233 |