| Conditions | 18 |
| Paths | 4609 |
| Total Lines | 86 |
| Code Lines | 43 |
| 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 |
||
| 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 | /* 12 Apr 2016 - PLEASE NOTE |
||
| 150 | We no longer just return the image html when "no link" option is chosen. |
||
| 151 | It was decided that it is better to return an anchor link with no href or target attributes. |
||
| 152 | This results in more standardized HTML output for better CSS and JS code |
||
| 153 | */ |
||
| 154 | |||
| 155 | // return $img; |
||
| 156 | } |
||
| 157 | |||
| 158 | if ( 'page' === $link ) { |
||
| 159 | //get the URL to the attachment page |
||
| 160 | $url = get_attachment_link( $this->ID ); |
||
| 161 | } else if ( 'custom' === $link ) { |
||
| 162 | $url = $args['custom_link']; |
||
| 163 | } else { |
||
| 164 | $url = $this->url; |
||
| 165 | } |
||
| 166 | |||
| 167 | //fallback for images that might not have a custom url |
||
| 168 | if ( empty( $url ) ) { |
||
| 169 | $url = $this->url; |
||
| 170 | } |
||
| 171 | |||
| 172 | $attr = array(); |
||
| 173 | |||
| 174 | //only add href and target attributes to the anchor if the link is NOT set to 'none' |
||
| 175 | if ( $link !== 'none' ){ |
||
| 176 | $attr['href'] = $url; |
||
| 177 | if ( ! empty( $this->custom_target ) && 'default' !== $this->custom_target ) { |
||
| 178 | $attr['target'] = $this->custom_target; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | if ( ! empty( $this->custom_target ) && 'default' !== $this->custom_target ) { |
||
| 183 | $attr['target'] = $this->custom_target; |
||
| 184 | } |
||
| 185 | |||
| 186 | if ( ! empty( $this->caption ) ) { |
||
| 187 | $attr['data-caption-title'] = $this->caption; |
||
| 188 | } |
||
| 189 | |||
| 190 | if ( !empty( $this->description ) ) { |
||
| 191 | $attr['data-caption-desc'] = $this->description; |
||
| 192 | } |
||
| 193 | |||
| 194 | $attr['data-attachment-id'] = $this->ID; |
||
| 195 | |||
| 196 | //pull any custom attributes out the args |
||
| 197 | if ( isset( $args['link_attributes'] ) && is_array( $args['link_attributes'] ) ) { |
||
| 198 | $attr = array_merge( $attr, $args['link_attributes'] ); |
||
| 199 | } |
||
| 200 | |||
| 201 | $attr = apply_filters( 'foogallery_attachment_html_link_attributes', $attr, $args, $this ); |
||
| 202 | $attr = array_map( 'esc_attr', $attr ); |
||
| 203 | $html = '<a '; |
||
| 204 | foreach ( $attr as $name => $value ) { |
||
| 205 | $html .= " $name=" . '"' . $value . '"'; |
||
| 206 | } |
||
| 207 | $html .= '>'; |
||
| 208 | if ( $output_image ) { |
||
| 209 | $html .= $img; |
||
| 210 | } |
||
| 211 | if ( $output_closing_tag ) { |
||
| 212 | $html .= '</a>'; |
||
| 213 | }; |
||
| 214 | |||
| 215 | return apply_filters( 'foogallery_attachment_html_link', $html, $args, $this ); |
||
| 216 | } |
||
| 217 | |||
| 245 |
This check looks for the bodies of
ifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
ifbodies can be removed. If you have an empty if but statements in theelsebranch, consider inverting the condition.could be turned into
This is much more concise to read.