Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 16 | class acf_field_oembed extends acf_field { |
||
| 17 | |||
| 18 | |||
| 19 | /* |
||
| 20 | * __construct |
||
| 21 | * |
||
| 22 | * This function will setup the field type data |
||
| 23 | * |
||
| 24 | * @type function |
||
| 25 | * @date 5/03/2014 |
||
| 26 | * @since 5.0.0 |
||
| 27 | * |
||
| 28 | * @param n/a |
||
| 29 | * @return n/a |
||
| 30 | */ |
||
|
|
|||
| 31 | |||
| 32 | View Code Duplication | function __construct() { |
|
| 57 | |||
| 58 | |||
| 59 | /* |
||
| 60 | * wp_oembed_get |
||
| 61 | * |
||
| 62 | * description |
||
| 63 | * |
||
| 64 | * @type function |
||
| 65 | * @date 24/01/2014 |
||
| 66 | * @since 5.0.0 |
||
| 67 | * |
||
| 68 | * @param $post_id (int) |
||
| 69 | * @return $post_id (int) |
||
| 70 | */ |
||
| 71 | |||
| 72 | function wp_oembed_get( $url = '', $width = 0, $height = 0 ) { |
||
| 102 | |||
| 103 | |||
| 104 | /* |
||
| 105 | * ajax_search |
||
| 106 | * |
||
| 107 | * description |
||
| 108 | * |
||
| 109 | * @type function |
||
| 110 | * @date 24/10/13 |
||
| 111 | * @since 5.0.0 |
||
| 112 | * |
||
| 113 | * @param $post_id (int) |
||
| 114 | * @return $post_id (int) |
||
| 115 | */ |
||
| 116 | |||
| 117 | function ajax_search() { |
||
| 158 | |||
| 159 | |||
| 160 | /* |
||
| 161 | * render_field() |
||
| 162 | * |
||
| 163 | * Create the HTML interface for your field |
||
| 164 | * |
||
| 165 | * @param $field - an array holding all the field's data |
||
| 166 | * |
||
| 167 | * @type action |
||
| 168 | * @since 3.6 |
||
| 169 | * @date 23/01/13 |
||
| 170 | */ |
||
| 171 | |||
| 172 | function render_field( $field ) { |
||
| 242 | |||
| 243 | |||
| 244 | /* |
||
| 245 | * render_field_settings() |
||
| 246 | * |
||
| 247 | * Create extra options for your field. This is rendered when editing a field. |
||
| 248 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 249 | * |
||
| 250 | * @param $field - an array holding all the field's data |
||
| 251 | * |
||
| 252 | * @type action |
||
| 253 | * @since 3.6 |
||
| 254 | * @date 23/01/13 |
||
| 255 | */ |
||
| 256 | |||
| 257 | function render_field_settings( $field ) { |
||
| 284 | |||
| 285 | |||
| 286 | /* |
||
| 287 | * format_value() |
||
| 288 | * |
||
| 289 | * This filter is appied to the $value after it is loaded from the db and before it is returned to the template |
||
| 290 | * |
||
| 291 | * @type filter |
||
| 292 | * @since 3.6 |
||
| 293 | * @date 23/01/13 |
||
| 294 | * |
||
| 295 | * @param $value (mixed) the value which was loaded from the database |
||
| 296 | * @param $post_id (mixed) the $post_id from which the value was loaded |
||
| 297 | * @param $field (array) the field array holding all the field options |
||
| 298 | * |
||
| 299 | * @return $value (mixed) the modified value |
||
| 300 | */ |
||
| 301 | |||
| 302 | function format_value( $value, $post_id, $field ) { |
||
| 320 | |||
| 321 | } |
||
| 322 | |||
| 328 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.